Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Worker<DataType, ResultType, NameType>

This class represents a worker that is able to process jobs from the queue. As soon as the class is instantiated and a connection to Redis is established it will start processing jobs.

Type parameters

  • DataType = any

  • ResultType = any

  • NameType: string = string

Hierarchy

Index

Constructors

  • new Worker<DataType, ResultType, NameType>(name: string, processor?: string | Processor<DataType, ResultType, NameType>, opts?: WorkerOptions, Connection?: typeof RedisConnection): Worker<DataType, ResultType, NameType>

Properties

closing: Promise<void>
keys: KeysMap
name: string
toKey: (type: string) => string

Type declaration

    • (type: string): string
    • Parameters

      • type: string

      Returns string

Accessors

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

    Returns Promise<RedisClient>

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

    Returns string

Methods

  • close(force?: boolean): Promise<void>
  • Closes the worker and related redis connections.

    This method waits for current jobs to finalize before returning.

    Parameters

    • force: boolean = false

      Use force boolean parameter if you do not want to wait for current jobs to be processed.

    Returns Promise<void>

    Promise that resolves when the worker has been closed.

  • delay(): Promise<void>
  • This function is exposed only for testing purposes.

    Returns Promise<void>

  • disconnect(): Promise<void>
  • emit<U>(event: U, ...args: Parameters<WorkerListener<DataType, ResultType, NameType>[U]>): boolean
  • getNextJob(token: string, __namedParameters?: GetNextJobOptions): Promise<Job<DataType, ResultType, NameType>>
  • Returns a promise that resolves to the next job in queue.

    Parameters

    • token: string

      worker token to be assigned to retrieved job

    • __namedParameters: GetNextJobOptions = {}

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

    a Job or undefined if no job was available in the queue.

  • isPaused(): boolean
  • Checks if worker is paused.

    Returns boolean

    true if worker is paused, false otherwise.

  • isRunning(): boolean
  • Checks if worker is currently running.

    Returns boolean

    true if worker is running, false otherwise.

  • off<U>(eventName: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): Worker<DataType, ResultType, NameType>
  • on<U>(event: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): Worker<DataType, ResultType, NameType>
  • once<U>(event: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): Worker<DataType, ResultType, NameType>
  • pause(doNotWaitActive?: boolean): Promise<void>
  • Pauses the processing of this queue only for this worker.

    Parameters

    • Optional doNotWaitActive: boolean

    Returns Promise<void>

  • processJob(job: Job<DataType, ResultType, NameType>, token: string, fetchNextCallback?: () => boolean): Promise<void | Job<DataType, ResultType, NameType>>
  • Parameters

    • job: Job<DataType, ResultType, NameType>
    • token: string
    • fetchNextCallback: () => boolean = ...
        • (): boolean
        • Returns boolean

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

  • resume(): void
  • run(): Promise<any[]>

Generated using TypeDoc