【问题标题】:Agenda job library, How to execute cron every last day of the month at mid night or last minute of the day议程作业库,如何在每个月的最后一天午夜或一天的最后一分钟执行 cron
【发布时间】:2020-05-03 23:50:54
【问题描述】:

议程作业库,请帮我在每个月的最后一天 23:50 运行 cron。

const cron = job.create('sendInvoice', {
      msg: 'Hello world',
});
await cron.repeatEvery('0 0 * * * *').repeatEvery('1 month').save(); //Executive daily

【问题讨论】:

    标签: javascript cron agenda


    【解决方案1】:

    首先,您需要一个针对您的案例的 cron 表达式(您可以使用在线生成器,例如 this one)。我还会定义作业,然后使用 every 安排它,而不是手动处理它(尽管也可以)。

    下面的代码应该按照你想要的方式工作:

    const Agenda = require('agenda');
    
    const agenda = new Agenda({ db: { address: /* your mongodb connection string */ } });
    
    agenda.define('yourJobName', (job) => {
      // do something
    }
    
    agenda.on('ready', () => {
      const schedule = '0 50 23 L * ? *'; // every last day of the month at 23:50
      agenda.every(schedule, 'yourJobName');
    }
    
    agenda.start();
    
    

    【讨论】:

    • 谢谢@kuba。我已经以其他方式实现了...但我会对此进行测试..感谢您的回答..
    • @NaisargParmar 让我知道情况如何,如果合适,请接受我的回答。
    猜你喜欢
    • 2016-01-02
    • 2011-09-02
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多