0
votes

Agenda job library, please help me to run cron on every last day of the month at 23:50.

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

1 Answers

1
votes

First of all, you'll need a cron expression for your case (you can use an online generator eg. this one). I would also define the job, and then schedule it with every instead of manually working with it (although it's possible too).

The following code should work the way you want it:

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();