NodeJS 议程计划程序未运行

o75abkj4  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(117)

我试图在特定日期安排一次性作业,但是,一旦到达日期,回调就不会被调用。作业被创建并添加到集合中。不确定我做错了什么。使用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();

字符串

6rvt4ljy

6rvt4ljy1#

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


100d1x

的字符串

bxjv4tth

bxjv4tth2#

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

相关问题