如何实现每五分钟执行一次定时任务
方法一
var rule = new schedule.RecurrenceRule();
rule.minute = new schedule.Range(0, 59, 5);
schedule.scheduleJob(rule, function(){
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
方法二
var event = schedule.scheduleJob("*/5 * * * *", function() {
console.log('This runs every 5 minutes');
});
经实验,*/5 * * * *
定时任务会在每5分钟的0秒执行。
每两小时执行一次
var event = schedule.scheduleJob("5 */2 * * *", function() {
console.log('This runs at minute 5 past every 2 hours');
});