'use strict';

/*
 * Application for sending RSS notifications to HipChat
 *
 * Usage:
 * 		1. Add your feeds to feeds.yml file.
 *    2. Copy .env.sample to .env and configure the required parameters
 *    3. Deploy to Heroku.
 *
 *   @author Bruno Paz <brunopaz@sapo.pt>
 *   @copyright Bruno Paz 2015
 */

var _ = require('underscore');
var utils = require('./lib/utils');
var FeedProcessor = require('./lib/feedProcessor');

var processor = new FeedProcessor();
var feeds = processor.loadFeeds();

// launch feed parsers
_.each(feeds, function(feedConfig, key) {
  var intervalInMillis = feedConfig.poll_interval * 1000;
  setInterval(function() {
    try {
        processor.process(key);
    } catch (err) {
        utils.log(err);
    }
  }, intervalInMillis);
});
