繁体   English   中英

议程作业库,如何在每个月的最后一天午夜或一天的最后一刻执行 cron

[英]Agenda job library, How to execute cron every last day of the month at mid night or last minute of the day

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

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

首先,您的案例需要一个 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM