Skip to main content
The Repeat class is deprecated and will be removed in v6. Use JobScheduler instead.

Overview

The Repeat class manages repeatable jobs that execute at specified intervals using cron patterns or fixed delays.
Access via queue.repeat property. For new implementations, use queue.jobScheduler instead.

Constructor

new Repeat(
  name: string,
  opts: RepeatBaseOptions
)

Methods

updateRepeatableJob

Updates or creates a repeatable job.
updateRepeatableJob<T, R, N>(
  name: N,
  data: T,
  opts: JobsOptions,
  config: { override: boolean }
): Promise<Job<T, R, N> | undefined>

getRepeatableJobs

Gets all repeatable jobs.
getRepeatableJobs(
  start?: number,
  end?: number,
  asc?: boolean
): Promise<RepeatableJob[]>
start
number
default:"0"
Offset of first job to return
end
number
default:"-1"
Offset of last job to return
asc
boolean
default:"false"
Return in ascending order by next execution time

removeRepeatable

Removes a repeatable job.
removeRepeatable(
  name: string,
  repeat: RepeatOptions,
  jobId?: string
): Promise<number>
name
string
required
Job name
repeat
RepeatOptions
required
Repeat options (must match the ones used when creating)
jobId
string
Optional job ID

removeRepeatableByKey

Removes a repeatable job by its key.
removeRepeatableByKey(key: string): Promise<number>
key
string
required
The repeatable job key (obtained from getRepeatableJobs)

getRepeatableCount

Gets the count of repeatable jobs.
getRepeatableCount(): Promise<number>

RepeatableJob

interface RepeatableJob {
  key: string;          // Unique key for the repeatable job
  name: string;         // Job name
  id?: string;          // Optional job ID
  endDate?: number;     // End date timestamp
  tz?: string;          // Timezone
  pattern?: string;     // Cron pattern
  every?: string;       // Interval
  next?: number;        // Next execution timestamp
}

Migration to JobScheduler

To migrate from Repeat to JobScheduler:

Old (Repeat)

await queue.add(
  'task',
  { data: 'value' },
  {
    repeat: {
      pattern: '0 * * * *',
    },
  }
);

const repeatableJobs = await queue.getRepeatableJobs();
await queue.removeRepeatable('task', { pattern: '0 * * * *' });

New (JobScheduler)

await queue.upsertJobScheduler(
  'task-scheduler',
  { pattern: '0 * * * *' },
  {
    name: 'task',
    data: { data: 'value' },
  }
);

const schedulers = await queue.getJobSchedulers();
await queue.removeJobScheduler('task-scheduler');

Example

import { Queue } from 'bullmq';

const queue = new Queue('myQueue', {
  connection: {
    host: 'localhost',
    port: 6379,
  },
});

// Access the repeat instance
const repeat = await queue.repeat;

// Get all repeatable jobs
const jobs = await repeat.getRepeatableJobs();

console.log(jobs);
// [
//   {
//     key: 'task:::0 * * * *',
//     name: 'task',
//     pattern: '0 * * * *',
//     next: 1234567890000
//   }
// ]

Build docs developers (and LLMs) love