Job Ids

All jobs in BullMQ need to have a unique job id. This id is used to construct a key to store the data in Redis, and as a pointer to the job as it is moved between the different states it can be in during its lifetime.

By default, job ids are generated automatically as an increasing counter, however it is also possible to specify a custom id.

The uniqueness requirement is scoped by queue, i.e. you can have the same job id in different queues without any issues. The counter for automatically generated ids is also scoped by queue.

The main reason to be able to specify a custom id is in cases when you want to avoid duplicated jobs. Since ids must be unique, if you add a job with an existing id then that job will just be ignored and not added to the queue at all.

In order to specify a custom job id, use the jobId option when adding jobs to the queue:

await myQueue.add(
  'wall',
  { color: 'pink' },
  {
    jobId: customJobId,
  },
);

Read more:

Last updated

Was this helpful?