Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Queue

Hierarchy

  • EventEmitter
    • Queue

Index

Constructors

constructor

  • new Queue(options: any, jobs?: {}): Queue

Properties

connection

connection: Connection

jobs

jobs: Jobs

options

Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Static captureRejections

captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Queue
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Queue

allDelayed

  • allDelayed(): Promise<{}>
    • jobsHash is an object with its keys being timestamps, and the values are arrays of jobs at each time.
    • note that this operation can be very slow and very ram-heavy

    Returns Promise<{}>

allWorkingOn

  • allWorkingOn(): Promise<{}>
    • returns a hash of the results of queue.workingOn with the worker names as keys.

    Returns Promise<{}>

cleanOldWorkers

  • cleanOldWorkers(age: number): Promise<{}>

connect

  • connect(): Promise<void>

del

  • del(q: string, func: string, args?: any[], count?: number): Promise<number>
    • jobs are deleted by those matching a func and argument collection within a given queue.
    • You might match none, or you might match many.

    Parameters

    • q: string
    • func: string
    • args: any[] = []
    • count: number = 0

    Returns Promise<number>

delByFunction

  • delByFunction(q: string, func: string, start?: number, stop?: number): Promise<number>
  • delByFunction

    • will delete all jobs in the given queue of the named function/class
    • will not prevent new jobs from being added as this method is running
    • will not delete jobs in the delayed queues

    Parameters

    • q: string

      queue to look in

    • func: string

      function name to delete any jobs with

    • start: number = 0

      optional place to start looking in list (default: beginning of list)

    • stop: number = -1

      optional place to end looking in list (default: end of list)

    Returns Promise<number>

    number of jobs deleted from queue

delDelayed

  • delDelayed(q: string, func: string, args?: any[]): Promise<any[]>
  • Parameters

    • q: string
    • func: string
    • args: any[] = []

    Returns Promise<any[]>

delLock

  • delLock(key: any): Promise<number>
    • count is an integer. You might delete more than one lock by the name.

    Parameters

    • key: any

    Returns Promise<number>

delQueue

  • delQueue(q: string): Promise<void>
    • delete a queue, and all jobs in that queue.

    Parameters

    • q: string

    Returns Promise<void>

delayedAt

  • delayedAt(timestamp: number): Promise<{ rTimestamp: number; tasks: any[] }>
    • jobsEnqueuedForThisTimestamp is an array, matching the style of the response of queue.queued

    Parameters

    • timestamp: number

    Returns Promise<{ rTimestamp: number; tasks: any[] }>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

encode

  • encode(q: string, func: string, args?: any[]): string

end

  • end(): Promise<void>

enqueue

  • enqueue(q: string, func: string, args?: any[]): Promise<any>
    • Enqueue a named job (defined in jobs to be worked by a worker)
    • The job will be added to the queueName queue, and that queue will be worked down by available workers assigned to that queue
    • args is optional, but should be an array of arguments passed to the job. Order of arguments is maintained

    Parameters

    • q: string
    • func: string
    • args: any[] = []

    Returns Promise<any>

enqueueAt

  • enqueueAt(timestamp: number, q: string, func: string, args?: any[], suppressDuplicateTaskError?: boolean): Promise<void>
    • In ms, the unix timestamp at which this job is able to start being worked on.
    • Depending on the number of other jobs in queueName, it is likely that this job will not be excecuted at exactly the time specified, but shortly thereafter.
    • other options the same as queue.enqueue

    Parameters

    • timestamp: number
    • q: string
    • func: string
    • args: any[] = []
    • suppressDuplicateTaskError: boolean = false

    Returns Promise<void>

enqueueIn

  • enqueueIn(time: number, q: string, func: string, args?: any[], suppressDuplicateTaskError?: boolean): Promise<void>
    • In ms, the number of ms to delay before this job is able to start being worked on.
    • Depending on the number of other jobs in queueName, it is likely that this job will not be excecuted at exactly the delay specified, but shortly thereafter.
    • other options the same as queue.enqueue

    Parameters

    • time: number
    • q: string
    • func: string
    • args: any[] = []
    • suppressDuplicateTaskError: boolean = false

    Returns Promise<void>

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

failed

  • failed(start: number, stop: number): Promise<any[]>
    • failedJobs is an array listing the data of the failed jobs. Each element looks like:
      {"worker": "host:pid", "queue": "test_queue", "payload": {"class":"slowJob", "queue":"test_queue", "args":[null]}, "exception": "TypeError", "error": "MyImport is not a function", "backtrace": [' at Worker.perform (/path/to/worker:111:24)', ' at <anonymous>'], "failed_at": "Fri Dec 12 2014 14:01:16 GMT-0800 (PST)"}\
      
    • To retrieve all failed jobs, use arguments: await queue.failed(0, -1)

    Parameters

    • start: number
    • stop: number

    Returns Promise<any[]>

failedCount

  • failedCount(): Promise<number>
    • failedCount is the number of jobs in the failed queue

    Returns Promise<number>

forceCleanWorker

  • forceCleanWorker(workerName: string): Promise<ErrorPayload>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

leader

  • leader(): Promise<string>

leaderKey

  • leaderKey(): string

length

  • length(q: string): Promise<number>
    • length is an integer counting the length of the jobs in the queue
    • this does not include delayed jobs for this queue

    Parameters

    • q: string

    Returns Promise<number>

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

locks

  • locks(): Promise<{}>
    • types of locks include queue and worker locks, as created by the plugins below
    • locks is a hash by type and timestamp

    Returns Promise<{}>

off

  • off(event: string | symbol, listener: (...args: any[]) => void): Queue
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Queue

on

  • on(event: "error", cb: (error: Error, queue: string) => void): Queue
  • Parameters

    • event: "error"
    • cb: (error: Error, queue: string) => void
        • (error: Error, queue: string): void
        • Parameters

          • error: Error
          • queue: string

          Returns void

    Returns Queue

once

  • once(event: "error", cb: (error: Error, queue: string) => void): Queue
  • Parameters

    • event: "error"
    • cb: (error: Error, queue: string) => void
        • (error: Error, queue: string): void
        • Parameters

          • error: Error
          • queue: string

          Returns void

    Returns Queue

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Queue
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Queue

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Queue
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Queue

queued

  • queued(q: string, start: number, stop: number): Promise<any[]>
    • list all the jobs (with their payloads) in a queue between start index and stop index.
    • jobs is an array containing the payload of the job enqueued

    Parameters

    • q: string
    • start: number
    • stop: number

    Returns Promise<any[]>

queues

  • queues(): Promise<string[]>
    • queues is an Array with the names of all your queues

    Returns Promise<string[]>

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): Queue
  • Parameters

    • Optional event: string | symbol

    Returns Queue

removeFailed

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Queue
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Queue

retryAndRemoveFailed

  • retryAndRemoveFailed(failedJob: ErrorPayload): Promise<any>

retryStuckJobs

  • retryStuckJobs(upperLimit?: number): Promise<void>
  • Look though the failed jobs to find those which were failed as a result of forceCleanWorker and re-enqueue them. This is potentially very slow if you have a lot of failed jobs

    Parameters

    • upperLimit: number = ...

    Returns Promise<void>

scheduledAt

  • scheduledAt(q: string, func: string, args?: any[]): Promise<any[]>
    • learn the timestamps at which a job is scheduled to be run.
    • timestampsForJob is an array of integers

    Parameters

    • q: string
    • func: string
    • args: any[] = []

    Returns Promise<any[]>

setMaxListeners

  • setMaxListeners(n: number): Queue
  • Parameters

    • n: number

    Returns Queue

stats

  • stats(): Promise<{}>
    • stats will be a hash containing details about all the queues in your redis, and how many jobs are in each, and who the leader is

    Returns Promise<{}>

timestamps

  • timestamps(): Promise<any[]>
    • timestamps is an array of integers for all timestamps which have at least one job scheduled in the future

    Returns Promise<any[]>

workers

  • workers(): Promise<{}>
    • returns a hash of the form: { 'host:pid': 'queue1, queue2', 'host:pid': 'queue1, queue2' }

    Returns Promise<{}>

workingOn

  • workingOn(workerName: any, queues: any): Promise<string>
    • returns: {"run_at":"Fri Dec 12 2014 14:01:16 GMT-0800 (PST)","queue":"test_queue","payload":{"class":"slowJob","queue":"test_queue","args":[null]},"worker":"workerA"}

    Parameters

    • workerName: any
    • queues: any

    Returns Promise<string>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static on

  • on(emitter: EventEmitter, event: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns AsyncIterableIterator<any>

Static once

  • once(emitter: NodeEventTarget, event: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string, options?: StaticEventEmitterOptions): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

Generated using TypeDoc