Skip to content

Getters

Source URL: https://docs.bullmq.io/guide/jobs/getters

When jobs are added to a queue, they will be in different statuses during their lifetime. BullMQ provides methods to retrieve information and jobs from the different statuses.

Diagram of the lifecycle of a BullMQ job in the queue

Lifecycle of a job

It is often necessary to know how many jobs are in a given status:

{% tabs %} {% tab title=“TypeScript” %}

import { Queue } from 'bullmq';
const myQueue = new Queue('Paint');
const counts = await myQueue.getJobCounts('wait', 'completed', 'failed');
// Returns an object like this { wait: number, completed: number, failed: number }

{% endtab %}

{% tab title=“Python” %}

from bullmq import Queue
myQueue = Queue('Paint')
counts = await myQueue.getJobCounts('wait', 'completed', 'failed')
# Returns an object like this { wait: number, completed: number, failed: number }

{% endtab %} {% endtabs %}

The available status are:

  • completed,
  • failed,
  • delayed,
  • active,
  • wait,
  • waiting-children,
  • prioritized,
  • paused, and
  • repeat.

It is also possible to retrieve the jobs with pagination style semantics. For example:

{% tabs %} {% tab title=“TypeScript” %}

const completed = await myQueue.getJobs(['completed'], 0, 100, true);
// returns the oldest 100 jobs

{% endtab %}

{% tab title=“Python” %}

completed = await myQueue.getJobs(['completed'], 0, 100, True)
# returns the oldest 100 jobs

{% endtab %} {% endtabs %}