-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 882 Bytes
/
index.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
const cron = require('node-cron');
const execSh = require('exec-sh');
const Ajv = require('ajv');
const ajv = new Ajv({allErrors: true});
const validate = ajv.compile({
type: 'array',
items: {
type: 'array',
minItems: 2,
items: {
type: 'string'
}
}
});
const tasks = require('./tasks.json');
const valid = validate(tasks);
if (!valid) {
console.error('Invalid tasks: ' + ajv.errorsText(validate.errors));
process.exit(1);
} else {
tasks.forEach(([expression, command], index) => {
cron.schedule(expression, () => {
execSh(command, {}, (err) => {
if (err) {
console.error(`Task ${index} exit code: ${err.code}`);
} else {
console.info(`Task ${index} completed`);
}
});
});
})
}