时间:2021-10-16 08:02:17 | 栏目:NodeJS | 点击:次
有的时候需要根据业务需要,晚上凌晨以后执行某些操作的时候,这个可能会有所帮助,我最近正在研究这个,欢迎共同探讨。
github地址:https://github.com/mattpat/node-schedule
一、安装
var j = schedule.scheduleJob(date, function(){
console.log('The world is going to end today.');
});
取消预设计划
[code]
j.cancel();
var rule = new schedule.RecurrenceRule();
rule.minute = 42;
var j = schedule.scheduleJob(rule, function(){
console.log('The answer to life, the universe, and everything!');
});
var j = schedule.scheduleJob(rule, function(){
console.log('Today is recognized by Rebecca Black!');
});
五、每秒执行
var times = [];
for(var i=1; i<60; i++){
times.push(i);
}
rule.second = times;
var c=0;
var j = schedule.scheduleJob(rule, function(){
c++;
console.log(c);
});