Dragonfly Cloud is now available in the AWS Marketplace - learn more

Question: How can I track the progress of a job in BullMQ?

Answer

In BullMQ, you can track the progress of a job by using the progress method. This is useful when dealing with long-running jobs where you'd like to provide some kind of feedback or persistence of progress over time.

To set the progress of a job, you would typically do it from within the process function itself:

queue.process(async (job) => { // Some processing here... // You can set the progress as an integer value or as an object await job.updateProgress(42); // or await job.updateProgress({ step: 1, totalSteps: 5 }); // Continue processing... });

You can also listen to the progress updates using on event listener:

job.on('progress', progress => { console.log(`Job ${job.id} is progressing: `, progress); });

Remember that the progress data you send can be any valid JSON data type. This means you could send an object with more complex and detailed information if needed, but keep in mind that this will increase the network overhead, so it's a balance between level of detail and performance impact.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost