我遇到了节点调度程序包Bull,并试图遵循指导方针来创建和示例并相应地执行我的cron作业。
index.js
const Queue = require("bull");
// 1. Initiating the Queue
const campaignQueue = new Queue("Campaign", {
redis: {
host: "127.0.0.1",
port: 6379,
},
});
const data = {
name: 'Connecting with user',
};
const start = new Date(Date.now() + 5000);
const end = new Date(start.getTime() + 5000);
const options = {
delay: 60000,
attempts: 2,
repeat: {
cron: "*/5 * * * * *",
tz: "America/Los_Angeles",
startDate: start,
endDate: end
}
};
// 2. Adding a Job to the Queue
campaignQueue.add('campaign one', data, options);
// 3. Consumer
campaignQueue.process(async (job) => {
console.log('print job value', job)
return await connectionScheduler(job);
});
// 4. Listener
campaignQueue.on('completed', (job, result) => {
console.log(`Job completed with result ${result}`);
})
//cron function that will execute on linkedin endpoint
function connectionScheduler(job) {
console.log('CRON started.....', job)
}
我已经尝试了很长时间了,但是无法解决。服务器启动后,控制台上没有任何输出。
感谢我的代码所缺乏的任何帮助或修复,谢谢。
除了cron表达式,一切对我来说都不错
尝试使用此cron表达式*/5 * * * *