node-schedule每天凌晨执行,为什么只执行一次就不执行了?
发布于 7 年前 作者 linkenliu 9470 次浏览 来自 问答

比如说2016-10-15 00:03:10执行了,但是2016-10-16 00:03:10就不执行了。

var j = schedule.scheduleJob('10 3 0 * * *', function () {
       console.log("执行任务.........");
   });
2 回复

应该是cron表达式写错了 10 3 0 ? * * 可使用 在线Cron表达式生成器进行表达式校验

感觉你的表达式没错,我用 0 0 22 * * * 来每天22点整跑,是完全可以的。javascript最好用cron-parser来校验表达式,很多在线的校验工具不太适合。

const parser = require('cron-parser');
const interval = parser.parseExpression('10 3 0 * * *');

//打印后面10次的执行时间
for (let i = 0; i < 10; ++i) {
	console.log(interval.next().toString());
}
回到顶部