-
Notifications
You must be signed in to change notification settings - Fork 16
River Initializers
In addition to a parser, you can also define an initializer function for your River. This function will be called once on program startup. This allows you to fetch any data you need on startup for your river to run. River View will not complete startup until each river initializer has called back.
To declare an initializer function, instead of your parse.js
module returning a function, have it return an object.
module.exports = {
initialize: function(callback) {
// do your initialization here, then callback();
},
parse: function(body, options, temporalDataCallback, metaDataCallback) {
}
};
The parse
function will be the same as described in Creating a River.
The initialize
function may also return a list of URLs representing the data sources for your river. In this case, the list of URLs will override the sources
value in the configuration file. You can see an example of this strategy in the airnow initialize
function, which looks like this:
function initialize(callback) {
var urls = [],
// As of today (Sep 7, 2015), there are 788 RSS feeds.
feedCount = 788;
_.times(feedCount, function(index) {
urls.push('http://feeds.airnowapi.org/rss/realtime/' + (index + 1) + '.xml');
});
callback(null, urls);
}
This initialize
function builds a list of URLs to RSS feeds, which prevents the need to fill up the config.yml
file with a bunch of URL values for the sources
.