Class Queue<DataTypeOrJob, DefaultResultType, DefaultNameType, DataType, ResultType, NameType>

Queue

This class provides methods to add jobs to a queue and some other high-level administration such as pausing or deleting queues.

Example

import { Queue } from 'bullmq';

interface MyDataType {
foo: string;
}

interface MyResultType {
bar: string;
}

const queue = new Queue<MyDataType, MyResultType, "blue" | "brown">('myQueue');

Type Parameters

Hierarchy (view full)

Constructors

Properties

closing: Promise<void>
jobsOpts: BaseJobOptions
keys: KeysMap
name: string

The name of the queue.

Options for the queue.

qualifiedName: string
toKey: ((type) => string)

Type declaration

    • (type): string
    • Parameters

      • type: string

      Returns string

token: string = ...

Accessors

  • get jobScheduler(): Promise<JobScheduler>
  • Returns Promise<JobScheduler>

  • get metaValues(): Record<string, string | number>
  • Returns Record<string, string | number>

  • get redisVersion(): string
  • Returns the version of the Redis instance the client is connected to,

    Returns string

Methods

  • Logs one row of job's log data.

    Parameters

    • jobId: string

      The job id to log against.

    • logRow: string

      String with log data to be logged.

    • Optional keepLogs: number

      Max number of log entries to keep (0 for unlimited).

    Returns Promise<number>

    The total number of log entries for this job so far.

  • Cleans jobs from a queue. Similar to drain but keeps jobs within a certain grace period.

    Parameters

    • grace: number

      The grace period in milliseconds

    • limit: number

      Max number of jobs to clean

    • type: "failed" | "active" | "paused" | "completed" | "wait" | "prioritized" | "delayed" = 'completed'

      The type of job to clean Possible values are completed, wait, active, paused, delayed, failed. Defaults to completed.

    Returns Promise<string[]>

    Id jobs from the deleted records

  • Returns the number of jobs waiting to be processed. This includes jobs that are "waiting" or "delayed" or "prioritized" or "waiting-children".

    Returns Promise<number>

  • Drains the queue, i.e., removes all jobs that are waiting or delayed, but not active, completed or failed.

    Parameters

    • delayed: boolean = false

      Pass true if it should also clean the delayed jobs.

    Returns Promise<void>

  • Returns the qualified job ids and the raw job data (if available) of the children jobs of the given parent job. It is possible to get either the already processed children, in this case an array of qualified job ids and their result values will be returned, or the pending children, in this case an array of qualified job ids will be returned. A qualified job id is a string representing the job id in a given queue, for example: "bull:myqueue:jobid".

    Parameters

    • parentId: string

      The id of the parent job

    • type: "pending" | "processed"

      "processed" | "pending"

    • start: number
    • end: number

    Returns Promise<{
        items: {
            err?: string;
            id: string;
            v?: any;
        }[];
        jobs: JobJsonRaw[];
        total: number;
    }>

  • Get global concurrency value. Returns null in case no value is set.

    Returns Promise<number>

  • Job counts by type

    Queue#getJobCountByTypes('completed') => completed count Queue#getJobCountByTypes('completed,failed') => completed + failed count Queue#getJobCountByTypes('completed', 'failed') => completed + failed count Queue#getJobCountByTypes('completed', 'waiting', 'failed') => completed + waiting + failed count

    Parameters

    Returns Promise<number>

  • Returns the job counts for each type specified or every list/set in the queue by default.

    Parameters

    Returns Promise<{
        [index: string]: number;
    }>

    An object, key (type) and value (count)

  • Returns the logs for a given Job.

    Parameters

    • jobId: string

      the id of the job to get the logs for.

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zero based index where to stop returning jobs.

    • asc: boolean = true

      if true, the jobs will be returned in ascending order.

    Returns Promise<{
        count: number;
        logs: string[];
    }>

  • Get all Job Schedulers

    Parameters

    • Optional start: number

      Offset of first scheduler to return.

    • Optional end: number

      Offset of last scheduler to return.

    • Optional asc: boolean

      Determine the order in which schedulers are returned based on their next execution time.

    Returns Promise<RepeatableJob[]>

  • Get current job state.

    Parameters

    • jobId: string

      job identifier.

    Returns Promise<"unknown" | JobState>

    Returns one of these values: 'completed', 'failed', 'delayed', 'active', 'waiting', 'waiting-children', 'unknown'.

  • Get queue metrics related to the queue.

    This method returns the gathered metrics for the queue. The metrics are represented as an array of job counts per unit of time (1 minute).

    Parameters

    • type: "failed" | "completed"
    • start: number = 0

      Start point of the metrics, where 0 is the newest point to be returned.

    • end: number = -1

      End point of the metrics, where -1 is the oldest point to be returned.

    Returns Promise<Metrics>

    • Returns an object with queue metrics.
  • Get queue events list related to the queue. Note: GCP does not support SETNAME, so this call will not work

    Returns Promise<{
        [index: string]: string;
    }[]>

    • Returns an array with queue events info.

    Deprecated

    do not use this method, it will be removed in the future.

  • Returns the time to live for a rate limited key in milliseconds.

    Parameters

    • Optional maxJobs: number

      max jobs to be considered in rate limit state. If not passed it will return the remaining ttl without considering if max jobs is excedeed.

    Returns Promise<number>

    -2 if the key does not exist. -1 if the key exists but has no associated expire.

  • Get all repeatable meta jobs.

    Parameters

    • Optional start: number

      Offset of first job to return.

    • Optional end: number

      Offset of last job to return.

    • Optional asc: boolean

      Determine the order in which jobs are returned based on their next execution time.

    Returns Promise<RepeatableJob[]>

    Deprecated

    This method is deprecated and will be removed in v6. Use getJobSchedulers instead.

  • Get library version.

    Returns Promise<string>

    the content of the meta.library field.

  • Get the worker list related to the queue. i.e. all the known workers that are available to process jobs for this queue. Note: GCP does not support SETNAME, so this call will not work

    Returns Promise<{
        [index: string]: string;
    }[]>

    • Returns an array with workers info.
  • Returns true if the queue is currently maxed.

    Returns Promise<boolean>

  • Returns true if the queue is currently paused.

    Returns Promise<boolean>

  • Completely destroys the queue and all of its contents irreversibly. This method will the pause the queue and requires that there are no active jobs. It is possible to bypass this requirement, i.e. not having active jobs using the "force" option.

    Note: This operation requires to iterate on all the jobs stored in the queue and can be slow for very large queues.

    Parameters

    Returns Promise<void>

  • Pauses the processing of this queue globally.

    We use an atomic RENAME operation on the wait queue. Since we have blocking calls with BRPOPLPUSH on the wait queue, as long as the queue is renamed to 'paused', no new jobs will be processed (the current ones will run until finalized).

    Adding jobs requires a LUA script to check first if the paused list exist and in that case it will add it there instead of the wait list.

    Returns Promise<void>

  • Promote all the delayed jobs.

    Parameters

    • opts: {
          count?: number;
      } = {}
      • Optional count?: number

    Returns Promise<void>

  • Overrides the rate limit to be active for the next jobs.

    Parameters

    • expireTimeMs: number

      expire time in ms of this rate limit.

    Returns Promise<void>

  • Removes the given job from the queue as well as all its dependencies.

    Parameters

    • jobId: string

      The id of the job to remove

    • opts: {
          removeChildren: boolean;
      } = {}

      Options to remove a job

      • removeChildren: boolean

    Returns Promise<number>

    1 if it managed to remove the job or 0 if the job or any of its dependencies were locked.

  • Removes a debounce key.

    Parameters

    • id: string

      identifier

    Returns Promise<number>

    Deprecated

    use removeDeduplicationKey

  • Removes a deduplication key.

    Parameters

    • id: string

      identifier

    Returns Promise<number>

  • Delete old priority helper key.

    Returns Promise<number>

  • Removes a job scheduler.

    Parameters

    • jobSchedulerId: string

    Returns Promise<boolean>

  • Removes rate limit key.

    Returns Promise<number>

  • Removes a repeatable job.

    Note: you need to use the exact same repeatOpts when deleting a repeatable job than when adding it.

    Parameters

    Returns Promise<boolean>

    Deprecated

    This method is deprecated and will be removed in v6. Use removeJobScheduler instead.

    See

    removeRepeatableByKey

  • Removes a repeatable job by its key. Note that the key is the one used to store the repeatable job metadata and not one of the job iterations themselves. You can use "getRepeatableJobs" in order to get the keys.

    Parameters

    • key: string

    Returns Promise<boolean>

    See

    getRepeatableJobs

    Deprecated

    This method is deprecated and will be removed in v6. Use removeJobScheduler instead.

  • Resumes the processing of this queue globally.

    The method reverses the pause operation by resuming the processing of the queue.

    Returns Promise<void>

  • Retry all the failed or completed jobs.

    Parameters

    • opts: {
          count?: number;
          state?: FinishedStatus;
          timestamp?: number;
      } = {}
      • Optional count?: number
      • Optional state?: FinishedStatus
      • Optional timestamp?: number

    Returns Promise<void>

  • Enable and set global concurrency value.

    Parameters

    • concurrency: number

      Maximum number of simultaneous jobs that the workers can handle. For instance, setting this value to 1 ensures that no more than one job is processed at any given time. If this limit is not defined, there will be no restriction on the number of concurrent jobs.

    Returns Promise<number>

  • Wraps the code with telemetry and provides a span for configuration.

    Type Parameters

    • T

    Parameters

    • spanKind: SpanKind

      kind of the span: Producer, Consumer, Internal

    • operation: string

      operation name (such as add, process, etc)

    • destination: string

      destination name (normally the queue name)

    • callback: ((span?, dstPropagationMetadata?) => T | Promise<T>)

      code to wrap with telemetry

        • (span?, dstPropagationMetadata?): T | Promise<T>
        • Parameters

          • Optional span: Span<any>
          • Optional dstPropagationMetadata: string

          Returns T | Promise<T>

    • Optional srcPropagationMetadata: string

    Returns Promise<T | Promise<T>>

  • Trim the event stream to an approximately maxLength.

    Parameters

    • maxLength: number

    Returns Promise<number>

  • Updates the given job's progress.

    Parameters

    • jobId: string

      The id of the job to update

    • progress: number | object

      Number or object to be saved as progress.

    Returns Promise<void>

  • Upserts a scheduler.

    A scheduler is a job factory that creates jobs at a given interval. Upserting a scheduler will create a new job scheduler or update an existing one. It will also create the first job based on the repeat options and delayed accordingly.

    Parameters

    • jobSchedulerId: NameType
    • repeatOpts: Omit<RepeatOptions, "key">

      Repeat options

    • Optional jobTemplate: {
          data?: DataType;
          name?: NameType;
          opts?: Omit<JobsOptions, "repeat" | "jobId" | "delay">;
      }

      Job template. If provided it will be used for all the jobs created by the scheduler.

    Returns Promise<Job<DataType, ResultType, NameType>>

    The next job to be scheduled (would normally be in delayed state).

Generated using TypeDoc