The type of the data that the job will process.
The type of the result of the job.
The type of the name of the job.
Optional
opts: QueueOptionsOptional
Connection: typeof RedisConnectionReadonly
nameThe name of the queue.
Options for the queue.
Readonly
qualifiedReturns a promise that resolves to a redis client. Normally used only by subclasses.
Returns this instance current default job options.
Returns the version of the Redis instance the client is connected to,
Adds a new job to the queue.
Name of the job to be added to the queue.
Arbitrary data to append to the job.
Optional
opts: JobsOptionsJob options that affects how the job is going to be processed.
Adds an array of jobs to the queue. This method may be faster than adding one job at a time in a sequence.
The array of jobs to add to the queue. Each job is defined by 3 properties, 'name', 'data' and 'opts'. They follow the same signature as 'Queue.add'.
Logs one row of job's log data.
The job id to log against.
String with log data to be logged.
Optional
keepLogs: numberMax number of log entries to keep (0 for unlimited).
The total number of log entries for this job so far.
Cleans jobs from a queue. Similar to drain but keeps jobs within a certain grace period.
The grace period in milliseconds
Max number of jobs to clean
The type of job to clean Possible values are completed, wait, active, paused, delayed, failed. Defaults to completed.
Id jobs from the deleted records
Close the queue instance.
Returns the number of jobs waiting to be processed. This includes jobs that are "waiting" or "delayed" or "prioritized" or "waiting-children".
Force disconnects a connection.
Drains the queue, i.e., removes all jobs that are waiting or delayed, but not active, completed or failed.
Pass true if it should also clean the delayed jobs.
Emits an event. Normally used by subclasses to emit events.
The emitted event.
Export the metrics for the queue in the Prometheus format. Automatically exports all the counts returned by getJobCounts().
Optional
globalVariables: Record<string, string>Returns the jobs that are in the "active" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in active status.
Returns the jobs that are in the "completed" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in completed status.
Returns the number of jobs per priority.
Get jobId from deduplicated state.
deduplication identifier
Returns the jobs that are in the "delayed" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in delayed status.
Returns the qualified job ids and the raw job data (if available) of the children jobs of the given parent job. It is possible to get either the already processed children, in this case an array of qualified job ids and their result values will be returned, or the pending children, in this case an array of qualified job ids will be returned. A qualified job id is a string representing the job id in a given queue, for example: "bull:myqueue:jobid".
The id of the parent job
"processed" | "pending"
an object with the following shape:
{ items: { id: string, v?: any, err?: string } [], jobs: JobJsonRaw[], total: number}
Returns the jobs that are in the "failed" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in failed status.
Get global concurrency value. Returns null in case no value is set.
Job counts by type
Queue#getJobCountByTypes('completed') => completed count Queue#getJobCountByTypes('completed,failed') => completed + failed count Queue#getJobCountByTypes('completed', 'failed') => completed + failed count Queue#getJobCountByTypes('completed', 'waiting', 'failed') => completed + waiting + failed count
Returns the job counts for each type specified or every list/set in the queue by default.
An object, key (type) and value (count)
Returns the logs for a given Job.
the id of the job to get the logs for.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
if true, the jobs will be returned in ascending order.
Returns the jobs that are on the given statuses (note that JobType is synonym for job status)
Get Job Scheduler by id
identifier of scheduler.
Get all Job Schedulers
Optional
start: numberOffset of first scheduler to return.
Optional
end: numberOffset of last scheduler to return.
Optional
asc: booleanDetermine the order in which schedulers are returned based on their next execution time.
Get the number of job schedulers.
The number of job schedulers.
Get current job state.
job identifier.
Returns one of these values: 'completed', 'failed', 'delayed', 'active', 'waiting', 'waiting-children', 'unknown'.
Get queue metrics related to the queue.
This method returns the gathered metrics for the queue. The metrics are represented as an array of job counts per unit of time (1 minute).
Start point of the metrics, where 0 is the newest point to be returned.
End point of the metrics, where -1 is the oldest point to be returned.
Returns the jobs that are in the "prioritized" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in prioritized status.
Returns the time to live for a rate limited key in milliseconds.
Optional
maxJobs: numbermax jobs to be considered in rate limit state. If not passed it will return the remaining ttl without considering if max jobs is excedeed.
-2 if the key does not exist. -1 if the key exists but has no associated expire.
Get all repeatable meta jobs.
Optional
start: numberOffset of first job to return.
Optional
end: numberOffset of last job to return.
Optional
asc: booleanDetermine the order in which jobs are returned based on their next execution time.
Get library version.
the content of the meta.library field.
Returns the jobs that are in the "waiting" status.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the jobs that are in the "waiting-children" status. I.E. parent jobs that have at least one child that has not completed yet.
zero based index from where to start returning jobs.
zero based index where to stop returning jobs.
Returns the number of jobs in waiting-children status.
Returns the number of jobs in waiting or paused statuses.
Get the worker list related to the queue. i.e. all the known workers that are available to process jobs for this queue. Note: GCP does not support SETNAME, so this call will not work
Returns the current count of workers for the queue.
getWorkersCount(): Promise
Returns true if the queue is currently maxed.
Returns true if the queue is currently paused.
Completely destroys the queue and all of its contents irreversibly. This method will the pause the queue and requires that there are no active jobs. It is possible to bypass this requirement, i.e. not having active jobs using the "force" option.
Note: This operation requires to iterate on all the jobs stored in the queue and can be slow for very large queues.
Optional
opts: ObliterateOptsObliterate options.
Pauses the processing of this queue globally.
We use an atomic RENAME operation on the wait queue. Since we have blocking calls with BRPOPLPUSH on the wait queue, as long as the queue is renamed to 'paused', no new jobs will be processed (the current ones will run until finalized).
Adding jobs requires a LUA script to check first if the paused list exist and in that case it will add it there instead of the wait list.
Promote all the delayed jobs.
An object with the following properties:
Overrides the rate limit to be active for the next jobs.
expire time in ms of this rate limit.
Removes the given job from the queue as well as all its dependencies.
The id of the job to remove
Options to remove a job
1 if it managed to remove the job or 0 if the job or any of its dependencies were locked.
Removes a deduplication key.
identifier
Delete old priority helper key.
Remove global concurrency value.
Removes a job scheduler.
identifier of the job scheduler.
Removes rate limit key.
Removes a repeatable job.
Note: you need to use the exact same repeatOpts when deleting a repeatable job than when adding it.
Job name
Repeat options
Optional
jobId: stringJob id to remove. If not provided, all jobs with the same repeatOpts
Removes a repeatable job by its key. Note that the key is the one used to store the repeatable job metadata and not one of the job iterations themselves. You can use "getRepeatableJobs" in order to get the keys.
Resumes the processing of this queue globally.
The method reverses the pause operation by resuming the processing of the queue.
Retry all the failed or completed jobs.
An object with the following properties:
Enable and set global concurrency value.
Maximum number of simultaneous jobs that the workers can handle. For instance, setting this value to 1 ensures that no more than one job is processed at any given time. If this limit is not defined, there will be no restriction on the number of concurrent jobs.
Wraps the code with telemetry and provides a span for configuration.
kind of the span: Producer, Consumer, Internal
operation name (such as add, process, etc)
destination name (normally the queue name)
code to wrap with telemetry
Optional
srcPropagationMetadata: stringTrim the event stream to an approximately maxLength.
Updates the given job's progress.
The id of the job to update
Number or object to be saved as progress.
Upserts a scheduler.
A scheduler is a job factory that creates jobs at a given interval. Upserting a scheduler will create a new job scheduler or update an existing one. It will also create the first job based on the repeat options and delayed accordingly.
Repeat options
Optional
jobTemplate: { data?: DataType; name?: NameType; opts?: JobSchedulerTemplateOptions }Job template. If provided it will be used for all the jobs created by the scheduler.
The next job to be scheduled (would normally be in delayed state).
Queue
This class provides methods to add jobs to a queue and some other high-level administration such as pausing or deleting queues.
Example