2015-12-09 07:02:08 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function BatchLauncher(batchManager) {
|
|
|
|
this.batchManager = batchManager;
|
|
|
|
this.batchInterval = global.settings.batch_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
BatchLauncher.prototype.start = function (interval) {
|
|
|
|
var self = this;
|
|
|
|
interval = this.batchInterval || interval || 5000;
|
|
|
|
|
|
|
|
this.intervalCallback = setInterval(function () {
|
2015-12-10 22:08:31 +08:00
|
|
|
self.batchManager.run(function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.log('Error in batch service: ', err);
|
|
|
|
}
|
|
|
|
});
|
2015-12-09 07:02:08 +08:00
|
|
|
}, interval);
|
|
|
|
};
|
|
|
|
|
|
|
|
BatchLauncher.prototype.stop = function () {
|
|
|
|
clearInterval(this.intervalCallback);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BatchLauncher;
|