Bull: Question: How to configure the schedules

Created on 23 Sep 2019  路  2Comments  路  Source: OptimalBits/bull

Description

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.

Minimal, Working Test code to reproduce the issue.

(An easy to reproduce test case will dramatically decrease the resolution time.)

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?

Bull version

3.11.0

Additional information

question

All 2 comments

Please try to use removeRepeatable method on a queue to remove schedule before re-adding it,

fetchQueue.removeRepeatable('second', {cron: '*/40 * * * *'})

Thanks, it worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DevBrent picture DevBrent  路  4Comments

ianstormtaylor picture ianstormtaylor  路  4Comments

tdzienniak picture tdzienniak  路  4Comments

JSRossiter picture JSRossiter  路  3Comments

weeco picture weeco  路  3Comments