Skip to content

Cancel Job

Grant Carthew edited this page Sep 29, 2016 · 8 revisions

Description

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.

Queue.cancelJob

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.

Queue.cancelJob Example

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))

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally