0

I'm using bull to run cron jobs with nodejs. This is my file, when debugging I only see first test job running every 2 minutes, but I dont see the other one. So here in my case I'm always getting test1 printed and never goes to the other job.

Can Anyone help please? thanks

const Queue = require('bull');

const queue = new Queue('test', 'redis://127.0.0.1:6379');

const transactionCron = async () => {
        const jobs = await queue.addBulk(['test',
            {
                action: 'test1',
            }, { repeat: { cron: "*/2 * * * *" } },
            {
                action: 'test2',
            }, { repeat: { cron: "* * * * *" } },
          
        ]);
    // console.log(queue, ' queue');
};



queue.process(async(job, done) => {
    console.log("transaction queue processing job");
    console.log(job.data.action);
    try {
        switch (job.data.action) {
            case 'test1':
                console.log((job.data.action) , "data");
                break;
            case 'test2':
                console.log(job.data.action, "data");
                break;
            
            default:
                logger.warn("Unknown job action", job);
                break;
        }
        done();

    } catch (error) {
        done(error);
    }
    
});
WebDev
  • 151
  • 1
  • 1
  • 8

1 Answers1

1

The parameter given to queue.addBulk() doesn't look correct, here is the addBulk() method signature: https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueaddBulk

It should be something like this:

await queue.addBulk([
  {
    data: { action: "test1" },
    opts: { repeat: { cron: "*/2 * * * *" } },
  },
  {
    data: { action: "test2" },
    opts: { repeat: { cron: "* * * * *" } },
  },
]);
Andrei
  • 4,289
  • 4
  • 25
  • 23