议程安排程序未运行

问题描述 投票:0回答:2

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


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();
node.js cron agenda
2个回答
1
投票

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


0
投票

如果您的议程调度程序未运行,请检查议程作业的数据库集合是否为空。

© www.soinside.com 2019 - 2024. All rights reserved.