Skip to main content

Overview

The Job class represents a job in the queue. Jobs are normally created implicitly when you add a job to the queue with Queue.add(), but a Job instance is also passed to the Worker’s process function.

Constructor

Jobs are typically created using Queue.add() rather than instantiating directly.

Properties

id

The unique identifier of the job.

name

The name of the job.

data

The payload data for this job.

opts

The options object for this job.

progress

The progress a job has performed so far.

returnvalue

The value returned by the processor when processing this job.

stacktrace

Stacktrace for the error (for failed jobs).

timestamp

Timestamp when the job was created.

attemptsMade

Number of attempts after the job has failed.

attemptsStarted

Number of times job has been moved to active state.

delay

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

priority

Ranges from 0 (highest priority) to 2,097,152 (lowest priority).

processedOn

Timestamp for when the job was processed.

finishedOn

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

failedReason

Reason for failing.

Static Methods

create

Creates a new job and adds it to the queue.

createBulk

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

fromId

Fetches a Job from the queue by ID.

Methods

updateProgress

Updates a job’s progress.
progress
number | object
required
Number or object to be saved as progress

updateData

Updates a job’s data.
data
any
required
The data that will replace the current job’s data

log

Logs one row of log data.
logRow
string
required
String with log data to be logged
count
number
The total number of log entries for this job

remove

Completely removes the job from the queue.
opts.removeChildren
boolean
default:"true"
Whether to remove child jobs

retry

Attempts to retry the job.
state
string
default:"'failed'"
The state from which to retry (completed or failed)
opts
RetryOptions
Retry options

promote

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

changeDelay

Changes the delay of a delayed job.
delay
number
required
Milliseconds from now when the job should be processed

changePriority

Changes the priority of a job.
opts.priority
number
New priority value
opts.lifo
boolean
Whether to add to the left (LIFO) or right (FIFO)

getState

Gets the current state of the job.
state
string
One of: ‘completed’, ‘failed’, ‘delayed’, ‘active’, ‘waiting’, ‘waiting-children’, ‘unknown’

isCompleted

Checks if the job has completed.

isFailed

Checks if the job has failed.

isDelayed

Checks if the job is delayed.

isActive

Checks if the job is active.

isWaiting

Checks if the job is waiting.

isWaitingChildren

Checks if the job is waiting for children.

getChildrenValues

Gets the result values of child jobs.

getDependencies

Gets children job keys if this job is a parent.

getDependenciesCount

Gets children job counts if this job is a parent.

waitUntilFinished

Returns a promise that resolves when the job has completed or rejects when failed.
queueEvents
QueueEvents
required
Instance of QueueEvents to listen for completion
ttl
number
Time in milliseconds to wait before timing out

moveToCompleted

Moves a job to the completed state.

moveToFailed

Moves a job to the failed state.

extendLock

Extends the lock for this job.
token
string
required
Unique token for the lock
duration
number
required
Lock duration in milliseconds