-
Notifications
You must be signed in to change notification settings - Fork 16
Cancel Job
For any number of reasons you may need to cancel a job currently in the queue. There are two ways you can do this; using Queue.cancelJob, or by calling next() passing a customized Error object.
This document explains the differences and when to use them.
The Queue.cancelJob method can be called while a job is in the queue with a waiting, failed, or active status. By calling the Queue.cancelJob method you will cause the job to change status to cancelled which will permanently prevent the job from being picked up for processing.
Note: You can reanimate jobs. See the Job Editing document for more detail.
If you are using rethinkdb-job-queue in a distributed environment and you have the change feed option enabled for your worker Queue objects, calling Queue.cancelJob will be received by all Queue objects. If you cancel the job from a Queue object that is not processing the job, and the job is being processed by another Queue object, a Queue.process callback called onCancel will be invoked. This will allow the Queue object processing the job to gracefully stop the processing of the job.
This example shows cancelling a job in the queue.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob()
q.addJob(job).catch((err) => {
console.error(err)
})
q.process((job, next, onCancel) => {
// Process your job here.
onCancel(job, () => {
// Gracefully stop your job here.
})
})
// Elsewhere in your code, cancel jobs.
// This can be on another process or host as long
// as the changeFeed option is enabled.
q.cancelJob(job).catch(err => console.error(err))- Introduction
- Tutorial
- Queue Constructor
- Queue Connection
- Queue Options
- Queue PubSub
- Queue Master
- Queue Events
- State Document
- Job Processing
- Job Options
- Job Status
- Job Retry
- Job Repeat
- Job Logging
- Job Editing
- Job Schema
- Job Name
- Complex Job
- Delayed Job
- Cancel Job
- Error Handling
- Queue.createJob
- Queue.addJob
- Queue.getJob
- Queue.findJob
- Queue.findJobByName
- Queue.containsJobByName
- Queue.cancelJob
- Queue.reanimateJob
- Queue.removeJob
- Queue.process
- Queue.review
- Queue.summary
- Queue.ready
- Queue.pause
- Queue.resume
- Queue.reset
- Queue.stop
- Queue.drop
- Queue.Job
- Queue.host
- Queue.port
- Queue.db
- Queue.name
- Queue.r
- Queue.id
- Queue.jobOptions [R/W]
- Queue.changeFeed
- Queue.master
- Queue.masterInterval
- Queue.removeFinishedJobs
- Queue.running
- Queue.concurrency [R/W]
- Queue.paused
- Queue.idle
- Event.ready
- Event.added
- Event.updated
- Event.active
- Event.processing
- Event.progress
- Event.log
- Event.pausing
- Event.paused
- Event.resumed
- Event.completed
- Event.cancelled
- Event.failed
- Event.terminated
- Event.reanimated
- Event.removed
- Event.idle
- Event.reset
- Event.error
- Event.reviewed
- Event.detached
- Event.stopping
- Event.stopped
- Event.dropped
- Job.setName
- Job.setPriority
- Job.setTimeout
- Job.setDateEnable
- Job.setRetryMax
- Job.setRetryDelay
- Job.setRepeat
- Job.setRepeatDelay
- Job.updateProgress
- Job.update
- Job.getCleanCopy
- Job.addLog
- Job.getLastLog