【问题标题】:Schedule jobs with Node-schedule使用 Node-schedule 调度作业
【发布时间】:2013-11-23 11:11:57
【问题描述】:

我正在使用一个名为 node-schedule 的节点模块

我有这个功能,预计在每季度开始时触发一次。

var rule = {hour: 0, minute: 0, day: 1, month: [0, 3, 6, 9]};

var logCost = schedule.scheduleJob(rule, function(){
  console.log('logCost output this shit at: ' + dateFormat(Date(), 'isoTime'));
});

问题在于该函数只是在一整天(即每月的第一天)中一直执行。我如何重新编写它以仅执行一次,我的规则变量可能有问题,但我看不出是什么。

【问题讨论】:

  • 如果有用,请采纳答案

标签: javascript node.js cron scheduled-tasks


【解决方案1】:

试试这个:

var rule = {hour: 00, minute: 01, dayOfWeek: 01, month: [0, 3, 6, 9]};
var logCost = schedule.scheduleJob(rule, function(){
          console.log('logCost output this shit at: ' + dateFormat(Date(), 'isoTime'));
});

检查这里: https://github.com/mattpat/node-schedule

应该是“dayOfWeek”,而不是“day”。

【讨论】:

    【解决方案2】:

    你也可以试试这个代码:

    var logCost = schedule.scheduleJob('1 0 * * *', function(){
      console.log('logCost output this shit at: ' + new Date());
    });
    

    上面的代码将在每天的 00:01 (12:01 AM) 执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      相关资源
      最近更新 更多