我每天早上12点使用以下job scheduler
代码打印Today is recognized by Rebecca Black!-
。
// executes every day at 12:AM
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, new schedule.Range(1, 6)];
rule.hour = 15;
rule.minute = 14;
schedule.scheduleJob(rule, function() {
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
如何每隔5
分钟打印一次
我使用以下方式,但它不起作用......
var rule = new schedule.RecurrenceRule();
rule.minute = 5;
schedule.scheduleJob(rule, function() {
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
答案 0 :(得分:31)
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!---------------------------');
});
答案 1 :(得分:9)
您可以使用cron format:
var event = schedule.scheduleJob("*/5 * * * *", function() {
console.log('This runs every 5 minutes');
});
cron格式包括:
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
答案 2 :(得分:2)