由于需要执行服务器定时任务,对比了下settimeout和setinterval后面还是选择了node-schedule,个人觉得还是挺方便的,但是缺点好像是不能支持多个node-schedule,希望有了解的朋友可以交流下。
1. node-schedule的安装 : npm install node-schedule
2. 开始执行定时任务
var schedule = require('node-schedule');
var request = require('request');
var rule = new schedule.RecurrenceRule();
var times = [5,10,15,20,25,30,35,40,45,50,55];
rule.second = times;//秒
// rule.hour = times;
var monitors = schedule.scheduleJob(rule, function () {
//执行定时调用接口任务
request.get(
{
url: 'http://localhost:5000/aa/matchs',
},
function (error, response, body) {
if (response.statusCode != undefined)
if (response.statusCode == 200) {
console.log("send BothWechat message success!");
}
}
);
});