0

I am trying to schedule a one-time job on a specific date, however, the callback never gets called once the date is reached. The job gets created and added to the collection. Not sure what I am doing wrong. Using agenda


const agenda = new Agenda({
  db: {address: '...', collection: 'agendaJobs'},
  useUnifiedTopology: true
});

agenda.on('ready', async () => {
   agenda.define("hello", 
    { priority: "high", concurrency: 20 },
    async (job) => {
      console.log("hello");
    });
});

async function start() {
  agenda.processEvery('1 second');
  await agenda.start();
  await agenda.schedule("in 10 seconds", "hello");
}

start();
joethemow
  • 1,641
  • 4
  • 24
  • 39

1 Answers1

0

package.json

{
  "name": "testing",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "agenda": "^4.2.1"
  }
}

index.js

const Agenda = require('agenda');

const mongoConnectionString = "mongodb://127.0.0.1/agenda";
const agenda = new Agenda({
  db: {address: mongoConnectionString},
  useUnifiedTopology: true
});

agenda.on('ready', async () => {
  console.log('connected');
});

agenda.define("hello", { priority: "high", concurrency: 20 }, async (job) => {
  console.log("hello");
});

(async function() {
  agenda.processEvery('1 second');
  await agenda.start();
  await agenda.schedule("in 10 seconds", "hello");
})();

enter image description here enter image description here

Chandan
  • 11,465
  • 1
  • 6
  • 25