forked from Hylozoic/hylo-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.js
57 lines (47 loc) · 1.19 KB
/
cron.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var skiff = require('./lib/skiff'), // this must be required first
moment = require('moment-timezone'),
rollbar = skiff.rollbar,
sails = skiff.sails,
Digest = require('./lib/community/digest'),
Promise = require('bluebird');
require('colors');
var jobs = {
daily: function() {
sails.log.debug('noop!');
return Promise.resolve(null);
},
hourly: function() {
var now = moment.tz('America/Los_Angeles');
switch (now.hour()) {
case 12:
sails.log.debug('Sending daily digests');
return Digest.sendDaily();
default:
return Promise.resolve(null);
}
},
every10minutes: function() {
sails.log.debug('noop!');
return Promise.resolve(null);
}
};
var runJob = Promise.method(function(name) {
var job = jobs[name];
if (typeof(job) !== 'function') {
throw new Error(format('Unknown job name: "%s"', name));
}
sails.log.debug(format('Running %s job', name));
return job();
});
skiff.lift({
start: function(argv) {
runJob(argv.interval).then(function() {
skiff.lower();
})
.catch(function(err) {
sails.log.error(err.message.red);
rollbar.handleError(err);
skiff.lower();
})
}
});