-
Notifications
You must be signed in to change notification settings - Fork 2
/
cron.js
39 lines (34 loc) · 854 Bytes
/
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
import { Meteor } from 'meteor/meteor';
import { SyncedCron } from 'meteor/littledata:synced-cron';
import { isAPIModule } from './apiModuleCommon';
import { PositionsCollection } from './PositionsCollection';
const tryRunJob = job => {
try {
return job();
} catch (e) {
console.error('Error running a job', e);
return 0;
}
};
Meteor.startup(() => {
console.time('cron');
if (!isAPIModule()) {
console.warn('** APP: SyncedCron are not started on www instance **');
console.timeEnd('cron');
return;
}
SyncedCron.config({
log: true,
});
SyncedCron.add({
name: 'Change positions',
schedule(parser) {
return parser.text('every 5 seconds');
},
job() {
return tryRunJob(() => PositionsCollection.updatePosition());
},
});
SyncedCron.start();
console.timeEnd('cron');
});