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 extends string = string

Hierarchy

  • Job

Constructors

  • Type Parameters

    • DataType = any

    • ReturnType = any

    • NameType extends string = string

    Parameters

    • queue: MinimalQueue
    • name: NameType

      The name of the Job

    • data: DataType

      The payload for this job.

    • opts: JobsOptions = {}

      The options object for this job.

    • Optional id: string

    Returns Job<DataType, ReturnType, NameType>

Properties

attemptsMade: number = 0

Number of attempts after the job has failed.

Default Value

0

data: DataType

The payload for this job.

delay: number

An amount of milliseconds to wait until this job can be processed.

Default Value

0

failedReason: string

Reason for failing.

finishedOn?: number

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

id?: string
name: NameType

The name of the Job

opts: JobsOptions = {}

The options object for this job.

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.

Default Value

0

repeatJobKey?: string

Base repeat job key.

returnvalue: ReturnType = null

The value returned by the processor when processing this job.

Default Value

null

stacktrace: string[] = null

Stacktrace for the error (for failed jobs).

Default Value

null

timestamp: number

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

Accessors

  • get prefix(): string
  • Returns

    the prefix that is used.

    Returns string

  • get queueName(): string
  • Returns

    the queue name this job belongs to.

    Returns string

Methods

  • Change delay of a delayed job.

    Returns

    void

    Parameters

    • delay: number

      milliseconds to be added to current time.

    Returns Promise<void>

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

    Returns void

  • Extend the lock for this job.

    Parameters

    • token: string

      unique token for the lock

    • duration: number

      lock duration in milliseconds

    Returns Promise<number>

  • Get this jobs children result values if any.

    Returns

    Object mapping children job keys with their values.

    Type Parameters

    • CT = any

    Returns Promise<{
        [jobKey: string]: CT;
    }>

  • Get children job keys if this job is a parent and has children.

    Returns

    dependencies separated by processed and unprocessed.

    Parameters

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

  • Get children job counts if this job is a parent and has children.

    Returns

    dependencies count separated by processed and unprocessed.

    Parameters

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

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

  • Get current state.

    Returns

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

    Returns Promise<"unknown" | JobState>

  • Returns

    true of the job is active.

    Returns Promise<boolean>

  • Returns

    true if the job has completed.

    Returns Promise<boolean>

  • Returns

    true if the job is delayed.

    Returns Promise<boolean>

  • Returns

    true if the job has failed.

    Returns Promise<boolean>

  • Returns

    true if the job is waiting.

    Returns Promise<boolean>

  • Returns

    true if the job is waiting for children.

    Returns Promise<boolean>

  • Logs one row of log data.

    Parameters

    • logRow: string

      string with log data to be logged.

    Returns Promise<number>

  • Moves a job to the completed queue. Returned job to be used with Queue.prototype.nextJobFromJobData.

    Returns

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

    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<any[]>

  • Moves the job to the delay set.

    Returns

    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>

  • Moves a job to the failed queue.

    Returns

    void

    Type Parameters

    • E extends 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>

  • Moves the job to the waiting-children set.

    Returns

    true if the job was moved

    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>

  • Promotes a delayed job so that it starts to be processed as soon as possible.

    Returns 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.

    Returns

    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

    Parameters

    Returns Promise<void>

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

  • Updates a job's data

    Parameters

    • data: DataType

      the data that will replace the current jobs data.

    Returns Promise<void>

  • Updates a job's progress

    Parameters

    • progress: number | object

      number or object to be saved as progress.

    Returns Promise<void>

  • 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.

    Returns

    Type Parameters

    • T = any

    • R = any

    • N extends 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.

    Returns

    Type Parameters

    • T = any

    • R = any

    • N extends 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.

    Returns

    Type Parameters

    • T = any

    • R = any

    • N extends 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)

    Returns

    Type Parameters

    • T = any

    • R = any

    • N extends 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