forked from invishantom/nCovMemory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.js
34 lines (33 loc) · 857 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
var child = require('child_process');
var CronJob = require('cron').CronJob;
const DATA = require('../data/index');
var diff = require('diff');
var fs = require('fs');
var path = require('path');
let execAsync = function(command, cwd) {
return new Promise((resolve, reject) => {
child.exec(command, { detached: true, windowsHide: true, cwd }, (e, o, err) => {
if (err) {
reject(err);
} else {
resolve(o);
}
});
});
};
var job = new CronJob(
'*/15 * * * * *',
async function() {
let oldCsv = fs.readFileSync(DATA['data'].path, 'utf8');
await execAsync('yarn fetch');
let newCsv = fs.readFileSync(DATA['data'].path, 'utf8');
if (oldCsv !== newCsv) {
await execAsync('yarn build');
await execAsync('yarn deploy');
}
},
null,
true,
'America/Los_Angeles'
);
job.start();