-1

我正在尝试在特定日期安排一次性工作,但是,一旦到达日期,回调就不会被调用。作业被创建并添加到集合中。不知道我做错了什么。使用议程


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

1 回答 1

0

包.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");
})();

在此处输入图像描述 在此处输入图像描述

于 2021-08-19T05:24:42.880 回答