Solo  当前访客:3 开始使用

node schedule cron表达式配置采坑记录


1. 使用node-shedule做任务调度,

按文档,是支持cron风格的时间配置, 结果发现并不是完全一样

 

例如:

0 0/10 * * * ?

执行cron的结果应该是:从0分钟开始,每10分钟执行一次

实际在node中执行结果是每小时的第0分钟执行了

 

2. 原因

node使用了 cron-parse库进行解析

我们可以在运行前使用以下代码进行检查是否正确

var parser = require('cron-parser');
function testCron () {
    var interval = parser.parseExpression('0 0/10 * * * ?');
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET)

}

testCron()


标题:node schedule cron表达式配置采坑记录
作者:hugh0524
地址:https://blog.uproject.cn/articles/2019/08/03/1564845101181.html

, , , , 0 0