Question: How can you configure job attempts in BullMQ?


In BullMQ, the number of job attempts or retries can be configured when adding a job to a queue. This can be useful when you want your jobs to be retried automatically if they fail.

Here is an example of how you can define a job with 3 attempts:

const someQueue = new Queue('someQueue'); someQueue.add( 'example', // job name { foo: 'bar' }, // job data { attempts: 3, // number of attempts backoff: { type: 'fixed', // type of backoff delay: 5000 // delay between attempts } } );

In this code, attempts: 3 means that the job will be retried up to three times if it fails. The backoff option sets how much time the queue should wait before retrying the job after a failure. In this case, it's set to a fixed delay of 5000 milliseconds (5 seconds).

If a job still fails after the maximum number of attempts, it's marked as failed and won't be processed again unless you manually retry it.

Please note that exception handling should be properly implemented in your job processing logic, so that exceptions are properly caught and handled. Uncaught exceptions might lead to unwanted behaviors.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.