Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Queue<DataType, ResultType, NameType>

Queue

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

Type parameters

  • DataType = any

  • ResultType = any

  • NameType: string = string

Hierarchy

Index

Constructors

Properties

closing: Promise<void>
jobsOpts: BaseJobOptions
keys: KeysMap
limiter: { groupKey: string } = null

Type declaration

  • groupKey: string
name: string
opts: QueueBaseOptions = {}
toKey: (type: string) => string

Type declaration

    • (type: string): string
    • Parameters

      • type: string

      Returns string

token: string = ...

Accessors

  • Returns a promise that resolves to a redis client. Normally used only by subclasses.

    Returns Promise<RedisClient>

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

    Returns string

Methods

  • add(name: NameType, data: DataType, opts?: JobsOptions): Promise<Job<DataType, ResultType, NameType>>
  • Adds a new job to the queue.

    Parameters

    • name: NameType

      Name of the job to be added to the queue,.

    • data: DataType

      Arbitrary data to append to the job.

    • Optional opts: JobsOptions

      Job options that affects how the job is going to be processed.

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

  • addBulk(jobs: { data: DataType; name: NameType; opts?: BulkJobOptions }[]): Promise<Job<DataType, ResultType, NameType>[]>
  • Adds an array of jobs to the queue. This method may be faster than adding one job at a time in a sequence.

    Parameters

    • jobs: { data: DataType; name: NameType; opts?: BulkJobOptions }[]

      The array of jobs to add to the queue. Each job is defined by 3 properties, 'name', 'data' and 'opts'. They follow the same signature as 'Queue.add'.

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

  • clean(grace: number, limit: number, type?: "completed" | "failed" | "active" | "delayed" | "paused" | "wait"): Promise<string[]>
  • Cleans jobs from a queue. Similar to drain but keeps jobs within a certain grace period.

    Parameters

    • grace: number

      The grace period

    • limit: number

      Max number of jobs to clean

    • type: "completed" | "failed" | "active" | "delayed" | "paused" | "wait" = '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

  • close(): Promise<void>
  • count(): Promise<number>
  • disconnect(): Promise<void>
  • drain(delayed?: boolean): Promise<void>
  • 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>

  • emit<U>(event: U, ...args: Parameters<QueueListener<DataType, ResultType, NameType>[U]>): boolean
  • getActive(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "active" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getActiveCount(): Promise<number>
  • getCompleted(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "completed" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getCompletedCount(): Promise<number>
  • getDelayed(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "delayed" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getDelayedCount(): Promise<number>
  • getFailed(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "failed" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getFailedCount(): Promise<number>
  • getJob(jobId: string): Promise<Job<DataType, ResultType, NameType>>
  • getJobCountByTypes(...types: JobType[]): 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>

  • getJobCounts(...types: JobType[]): Promise<{}>
  • getJobLogs(jobId: string, start?: number, end?: number, asc?: boolean): Promise<{ count: number; logs: [string] }>
  • 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

      zeroo 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] }>

  • getJobs(types?: JobType | JobType[], start?: number, end?: number, asc?: boolean): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are on the given statuses (note that JobType is synonym for job status)

    Parameters

    • Optional types: JobType | JobType[]

      the statuses of the jobs to return.

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

    • asc: boolean = false

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

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

  • getMetrics(type: "completed" | "failed", start?: number, end?: number): Promise<Metrics>
  • 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: "completed" | "failed"
    • 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.
  • getQueueEvents(): Promise<{}[]>
  • getQueueSchedulers(): Promise<{}[]>
  • getRanges(types: JobType[], start?: number, end?: number, asc?: boolean): Promise<string[]>
  • getRepeatableJobs(start?: number, end?: number, asc?: boolean): Promise<{ cron: string; endDate: number; id: string; key: string; name: string; next: number; tz: string }[]>
  • 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<{ cron: string; endDate: number; id: string; key: string; name: string; next: number; tz: string }[]>

  • getWaiting(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "waiting" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getWaitingChildren(start?: number, end?: number): Promise<Job<DataType, ResultType, NameType>[]>
  • Returns the jobs that are in the "waiting" status.

    Parameters

    • start: number = 0

      zero based index from where to start returning jobs.

    • end: number = -1

      zeroo based index where to stop returning jobs.

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

  • getWaitingChildrenCount(): Promise<number>
  • getWaitingCount(): Promise<number>
  • getWorkers(): Promise<{}[]>
  • Get the worker list related to the queue. i.e. all the known workers that are available to process jobs for this queue.

    Returns Promise<{}[]>

    • Returns an array with workers info.
  • isPaused(): 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>

  • off<U>(eventName: U, listener: QueueListener<DataType, ResultType, NameType>[U]): Queue<DataType, ResultType, NameType>
  • on<U>(event: U, listener: QueueListener<DataType, ResultType, NameType>[U]): Queue<DataType, ResultType, NameType>
  • once<U>(event: U, listener: QueueListener<DataType, ResultType, NameType>[U]): Queue<DataType, ResultType, NameType>
  • pause(): 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>

  • remove(jobId: string): Promise<number>
  • Removes the given job from the queue as well as all its dependencies.

    Parameters

    • jobId: string

      The id of the job to remove

    Returns Promise<number>

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

  • removeRepeatable(name: NameType, repeatOpts: RepeatOptions, jobId?: string): Promise<boolean>
  • Removes a repeatable job.

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

    see

    removeRepeatableByKey

    Parameters

    Returns Promise<boolean>

  • removeRepeatableByKey(key: string): Promise<boolean>
  • 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.

    see

    getRepeatableJobs

    Parameters

    • key: string

      to the repeatable job.

    Returns Promise<boolean>

  • resume(): Promise<void>
  • Resumes the processing of this queue globally.

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

    Returns Promise<void>

  • retryJobs(opts?: { count?: number; state?: FinishedStatus; timestamp?: number }): Promise<void>
  • Retry all the failed jobs.

    Parameters

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

      contains number to limit how many jobs will be moved to wait status per iteration, state (failed, completed) failed by default or from which timestamp.

      • Optional count?: number
      • Optional state?: FinishedStatus
      • Optional timestamp?: number

    Returns Promise<void>

  • trimEvents(maxLength: number): Promise<number>
  • Trim the event stream to an approximately maxLength.

    Parameters

    • maxLength: number

    Returns Promise<number>

Generated using TypeDoc