Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Job<DataType, ReturnType, NameType>

Job

This class represents a Job in the queue. Normally job are implicitly created when you add a job to the queue with methods such as Queue.addJob( ... )

A Job instance is also passed to the Worker's process function.

Type parameters

  • DataType = any

  • ReturnType = any

  • NameType: string = string

Hierarchy

  • Job

Index

Constructors

  • new Job<DataType, ReturnType, NameType>(queue: MinimalQueue, name: NameType, data: DataType, opts?: JobsOptions, id?: string): Job<DataType, ReturnType, NameType>
  • Type parameters

    • DataType = any

    • ReturnType = any

    • NameType: string = string

    Parameters

    Returns Job<DataType, ReturnType, NameType>

Properties

attemptsMade: number = 0

Number of attempts after the job has failed.

defaultvalue

0

data: DataType
failedReason: string

Reason for failing.

finishedOn?: number

Timestamp for when the job finished (completed or failed).

id?: string
name: NameType
opts: JobsOptions = {}
parent?: ParentKeys

Object that contains parentId (id) and parent queueKey.

parentKey?: string

Fully qualified key (including the queue prefix) pointing to the parent of this job.

processedOn?: number

Timestamp for when the job was processed.

progress: number | object = 0

The progress a job has performed so far.

defaultvalue

0

repeatJobKey?: string

Base repeat job key.

returnvalue: ReturnType = null

The value returned by the processor when processing this job.

defaultvalue

null

stacktrace: string[] = null

Stacktrace for the error (for failed jobs).

defaultvalue

null

timestamp: number

Timestamp when the job was created (unless overridden with job options).

Accessors

  • get prefix(): string
  • get queueName(): string

Methods

  • changeDelay(delay: number): Promise<void>
  • Change delay of a delayed job.

    Parameters

    • delay: number

      milliseconds to be added to current time.

    Returns Promise<void>

    void

  • discard(): void
  • Marks a job to not be retried if it fails (even if attempts has been configured)

    Returns void

  • extendLock(token: string, duration: number): Promise<number>
  • Extend the lock for this job.

    Parameters

    • token: string

      unique token for the lock

    • duration: number

      lock duration in milliseconds

    Returns Promise<number>

  • getChildrenValues<CT>(): Promise<{}>
  • Get this jobs children result values if any.

    Type parameters

    • CT = any

    Returns Promise<{}>

    Object mapping children job keys with their values.

  • getDependencies(opts?: DependenciesOpts): Promise<{ nextProcessedCursor?: number; nextUnprocessedCursor?: number; processed?: Record<string, any>; unprocessed?: string[] }>
  • Get children job keys if this job is a parent and has children.

    Parameters

    Returns Promise<{ nextProcessedCursor?: number; nextUnprocessedCursor?: number; processed?: Record<string, any>; unprocessed?: string[] }>

    dependencies separated by processed and unprocessed.

  • getDependenciesCount(opts?: { processed?: boolean; unprocessed?: boolean }): Promise<{ processed?: number; unprocessed?: number }>
  • Get children job counts if this job is a parent and has children.

    Parameters

    • opts: { processed?: boolean; unprocessed?: boolean } = {}
      • Optional processed?: boolean
      • Optional unprocessed?: boolean

    Returns Promise<{ processed?: number; unprocessed?: number }>

    dependencies count separated by processed and unprocessed.

  • getState(): Promise<JobState | "unknown">
  • Get current state.

    Returns Promise<JobState | "unknown">

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

  • isActive(): Promise<boolean>
  • isCompleted(): Promise<boolean>
  • isDelayed(): Promise<boolean>
  • isFailed(): Promise<boolean>
  • isWaiting(): Promise<boolean>
  • isWaitingChildren(): Promise<boolean>
  • Returns Promise<boolean>

    true if the job is waiting for children.

  • log(logRow: string): Promise<number>
  • Logs one row of log data.

    Parameters

    • logRow: string

      string with log data to be logged.

    Returns Promise<number>

  • moveToCompleted(returnValue: ReturnType, token: string, fetchNext?: boolean): Promise<[] | JobData>
  • Moves a job to the completed queue. Returned job to be used with Queue.prototype.nextJobFromJobData.

    Parameters

    • returnValue: ReturnType

      The jobs success message.

    • token: string

      Worker token used to acquire completed job.

    • fetchNext: boolean = true

      True when wanting to fetch the next job.

    Returns Promise<[] | JobData>

    Returns the jobData of the next job in the waiting queue.

  • moveToDelayed(timestamp: number, token?: string): Promise<void>
  • Moves the job to the delay set.

    Parameters

    • timestamp: number

      timestamp where the job should be moved back to "wait"

    • Optional token: string

      token to check job is locked by current worker

    Returns Promise<void>

  • moveToFailed<E>(err: E, token: string, fetchNext?: boolean): Promise<void>
  • Moves a job to the failed queue.

    Type parameters

    • E: Error

    Parameters

    • err: E

      the jobs error message.

    • token: string

      token to check job is locked by current worker

    • fetchNext: boolean = false

      true when wanting to fetch the next job

    Returns Promise<void>

    void

  • Moves the job to the waiting-children set.

    Parameters

    • token: string

      Token to check job is locked by current worker

    • opts: MoveToWaitingChildrenOpts = {}

      The options bag for moving a job to waiting-children.

    Returns Promise<boolean>

    true if the job was moved

  • promote(): Promise<void>
  • Promotes a delayed job so that it starts to be processed as soon as possible.

    Returns Promise<void>

  • remove(): Promise<void>
  • Completely remove the job from the queue. Note, this call will throw an exception if the job is being processed when the call is performed.

    Returns Promise<void>

  • Attempts to retry the job. Only a job that has failed or completed can be retried.

    Parameters

    Returns Promise<void>

    If resolved and return code is 1, then the queue emits a waiting event otherwise the operation was not a success and throw the corresponding error. If the promise rejects, it indicates that the script failed to execute

  • toJSON(): Omit<Job<DataType, ReturnType, NameType>, "prefix" | "queueName" | "queue" | "scripts" | "toJSON" | "asJSON" | "asJSONSandbox" | "update" | "updateProgress" | "log" | "remove" | "extendLock" | "moveToCompleted" | "moveToFailed" | "isCompleted" | "isFailed" | "isDelayed" | "isWaitingChildren" | "isActive" | "isWaiting" | "getState" | "changeDelay" | "getChildrenValues" | "getDependencies" | "getDependenciesCount" | "waitUntilFinished" | "moveToDelayed" | "moveToWaitingChildren" | "promote" | "retry" | "discard" | "addJob">
  • Returns Omit<Job<DataType, ReturnType, NameType>, "prefix" | "queueName" | "queue" | "scripts" | "toJSON" | "asJSON" | "asJSONSandbox" | "update" | "updateProgress" | "log" | "remove" | "extendLock" | "moveToCompleted" | "moveToFailed" | "isCompleted" | "isFailed" | "isDelayed" | "isWaitingChildren" | "isActive" | "isWaiting" | "getState" | "changeDelay" | "getChildrenValues" | "getDependencies" | "getDependenciesCount" | "waitUntilFinished" | "moveToDelayed" | "moveToWaitingChildren" | "promote" | "retry" | "discard" | "addJob">

  • update(data: DataType): Promise<void>
  • Updates a job's data

    Parameters

    • data: DataType

      the data that will replace the current jobs data.

    Returns Promise<void>

  • updateProgress(progress: number | object): Promise<void>
  • Updates a job's progress

    Parameters

    • progress: number | object

      number or object to be saved as progress.

    Returns Promise<void>

  • waitUntilFinished(queueEvents: QueueEvents, ttl?: number): Promise<ReturnType>
  • Returns a promise the resolves when the job has completed (containing the return value of the job), or rejects when the job has failed (containing the failedReason).

    Parameters

    • queueEvents: QueueEvents

      Instance of QueueEvents.

    • Optional ttl: number

      Time in milliseconds to wait for job to finish before timing out.

    Returns Promise<ReturnType>

  • Creates a new job and adds it to the queue.

    Type parameters

    • T = any

    • R = any

    • N: string = string

    Parameters

    • queue: MinimalQueue

      the queue where to add the job.

    • name: N

      the name of the job.

    • data: T

      the payload of the job.

    • Optional opts: JobsOptions

      the options bag for this job.

    Returns Promise<Job<T, R, N>>

  • Creates a bulk of jobs and adds them atomically to the given queue.

    Type parameters

    • T = any

    • R = any

    • N: string = string

    Parameters

    • queue: MinimalQueue

      -the queue were to add the jobs.

    • jobs: { data: T; name: N; opts?: BulkJobOptions }[]

      an array of jobs to be added to the queue.

    Returns Promise<Job<T, R, N>[]>

  • Fetches a Job from the queue given the passed job id.

    Type parameters

    • T = any

    • R = any

    • N: string = string

    Parameters

    • queue: MinimalQueue

      the queue where the job belongs to.

    • jobId: string

      the job id.

    Returns Promise<Job<T, R, N>>

  • Instantiates a Job from a JobJsonRaw object (coming from a deserialized JSON object)

    Type parameters

    • T = any

    • R = any

    • N: string = string

    Parameters

    • queue: MinimalQueue

      the queue where the job belongs to.

    • json: JobJsonRaw

      the plain object containing the job.

    • Optional jobId: string

      an optional job id (overrides the id coming from the JSON object)

    Returns Job<T, R, N>

Generated using TypeDoc