I would like to trigger certain jobs at specific intervals. I thought of using queue.empty() but it is not adding an new entries at all. Here is the code I tried.
const Queue = require('bull');
const fetchQueue = new Queue('Second Queue', {
limiter: {
max: 10,
duration: 600
}
});
async function configure() {
//await fetchQueue.empty();
let firstJob = fetchQueue.add("first", {name: "earthQuakeAlert"}, {repeat: {cron: '*/40 * * * *'}});
let secondJob = fetchQueue.add("second", {name: "lightening 1"}, {repeat: {cron: '*/50 * * * *'}});
let thirdJob = fetchQueue.add("third", {name: "weatherAlert"}, {repeat: {cron: '*/10 * * * *'}});
let forthJob = fetchQueue.add("fourth", {name: "lightening 2"}, {repeat: {cron: '*/15 * * * *'}});
let fifthJob = fetchQueue.add("fifth", {name: "lightening 3"}, {repeat: {cron: '*/20 * * * *'}});
let sixJob = fetchQueue.add("sixth", {name: "tornado"}, {repeat: {cron: '*/25 * * * *'}});
await Promise.all([firstJob, secondJob, thirdJob, forthJob, fifthJob, sixJob]).catch(console.error);
}
configure();
In the above code, if I empty the queue, I see that the queue is emptied and no new job is present in the Delayed queue. Without emptying the queue, only the modified jobs are added again. So basically updating the schedule adds a new entry into the Delayed queue rather than modifying the current one.
What is the best approach for updating the job schedule?
3.11.0
Please try to use removeRepeatable method on a queue to remove schedule before re-adding it,
fetchQueue.removeRepeatable('second', {cron: '*/40 * * * *'})
Thanks, it worked.