-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScheduler.js
37 lines (25 loc) · 880 Bytes
/
Scheduler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const schedule = require('node-schedule');
const EventDispatcher = require('./src/queue-event/event-dispatcher');
let schedulerFiles = __dirname + '/src/schedulers';
const dispatcher = new EventDispatcher();
dispatcher.init()
.then(() => {
fs.readdir(schedulerFiles, function (err, files) {
let pending = [];
for (let i = 0; i < files.length; i++) {
// only include .js files
if (!files[i].match(/\.js$/)) {
continue;
}
let file = path.join(schedulerFiles, files[i]);
let scheduler = require(file)(dispatcher);
pending.push(schedule.scheduleJob(scheduler.rule, scheduler.task));
}
console.log('Scheduling all schedulers.');
return Promise.all(pending);
});
});