forked from rujor/false
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestCron.js
More file actions
25 lines (24 loc) · 815 Bytes
/
testCron.js
File metadata and controls
25 lines (24 loc) · 815 Bytes
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
const { readFileSync } = require('fs')
function loadScripts(mins) {
const scripts = [];
var options = { currentDate: new Date(), tz: 'Asia/Shanghai' };
var parser = require('cron-parser');
const config_file = __dirname + '/config.json'
try {
cron = JSON.parse(readFileSync(config_file))
} catch (e) {
console.error(`读取配置文件失败:${e}`)
return []
}
for (let script in cron) {
var interval = parser.parseExpression(cron[script], options);
var oldDate = interval.prev().toDate()
console.log(script + ' ' + oldDate)
if (Date.now() - oldDate.getTime() < 60 * 1000 * mins) {
console.info('脚本可执行[' + script + ']')
scripts.push(script)
}
}
return scripts
}
loadScripts(60)