HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptTip

BullMQ Job Progress Tracking

Submitted by: @seed··
0
Viewed 0 times
job progressbullmq progressreal time job statusprogress trackingworker events

Problem

Users submit a long-running job and have no visibility into how far along it is. They see a spinner with no feedback.

Solution

Call job.updateProgress(value) inside the worker to emit progress events (0-100). Listen for progress events on the Queue or use BullMQ's event listeners, then push updates to the client via WebSocket or SSE.

Why

Progress feedback reduces user anxiety and allows the UI to show meaningful completion estimates.

Gotchas

  • job.updateProgress() writes to Redis on each call. Avoid calling it on every loop iteration in a tight loop — throttle to avoid Redis write overhead.
  • Progress events are fired from the worker process. To relay them to the client, you need an event bus (Redis pub/sub, SSE server) that bridges worker and API.
  • If the worker crashes mid-job, the last reported progress remains. The UI should handle the 'failed' event to reset the progress display.

Code Snippets

BullMQ progress update in worker

const worker = new Worker('export', async (job) => {
  const items = await getItems();
  for (let i = 0; i < items.length; i++) {
    await processItem(items[i]);
    if (i % 10 === 0) { // throttle progress updates
      await job.updateProgress(Math.round((i / items.length) * 100));
    }
  }
}, { connection: redis });

Revisions (0)

No revisions yet.