0
const mongoconection =url;

const agenda = new Agenda({
  db: {
    address: mongoconection,
    collection: "agendajobs",
    option: { useUnifiedTopology: true }
  }
});

new Promise(resolve=> agenda.once('ready', resolve));

agenda.define("say hello", job => {
  console.log('hello');
});

(async function() {
  await agenda.start();

  await agenda.schedule(4/2/2020, 'say hello');
  //repeat every
})();

how can I pass the dynamic date to the agenda?`` it's falling if I give in this formate 4/2/2020 If I give 5 minutes or even once a week if working can anyone help me how to give time and specified date

1 Answers1

0

Since schedule(when, name, [data]) as per the documentation

[s]chedules a job to run name once at a given time. when can be a Date or a String such as tomorrow at 5pm.

You need to provide a Date object instead of String. The way to do it as per Date MDN documentation is new Date(2020, 1, 4) (assuming you meant February and not April) so your line could be:

agenda.schedule(new Date(2020, 1, 4), 'say hello');