我正在运行一个MEAN堆栈应用程序,并且正在努力正确执行重复发生的任务。我已将以下行添加到我的server.js文件中:
require('./node_scripts/schedule/node_sched.js');
然后指向此文件:
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
rule.minute = 57;
var notify = schedule.scheduleJob(rule, function(){
var notifyScript = require('../arrival_checker/arrival_main.js');
console.log('Ran notify script ' + new Date());
notifyScript;
});
该脚本成功运行一次,但从未再次运行。以下是我的问题:
答案 0 :(得分:-1)
我认为以下代码会对您有所帮助。以下代码将每00:01(午夜)执行。
var schedule = require('node-schedule');
schedule.scheduleJob('1 0 * * *', function () {
console.log('Ran notify script ' + new Date());
})
您还可以创建自己的规则以提供执行时间:
var yourRule = {hour: 0, minute: 0, dayOfWeek: 1, month: [0, 3, 6, 9]};
var scheduleFunction = schedule.scheduleJob(yourRule, function(){
console.log('will execute every quarter'));
});
链接制定您自己的规则:https://www.npmjs.com/package/node-schedule