Skip to content

Queue.removeJob

Grant Carthew edited this page Oct 4, 2016 · 6 revisions

Method Signature

Queue.removeJob(JobOrId)

Parameter: JobOrId Object or String or Array

  • A single Job or Id, or an array of Jobs or Ids.

Returns: Promise => Array

  • An array of job ids that have been removed.

Example:

q.removeJob(jobs).then((removedJobIds) => {
  // removedJobIds is an array of one or more ids of the removed jobs
}).catch(err => console.error(err))

Description

If you are trying to clean up your queue backing table you have two options. You can call Queue.reset to remove all the jobs or Queue.removeJob to remove just a specified list of jobs. Be warned though, Queue.reset will remove all the jobs including jobs that have not been processed.

If you like the idea of Queue.reset, consider looking at Queue.summary first.

If wiping out the whole queue it a little too heavy for you, then get the list of ids or jobs you want to remove and call Queue.removeJob.

Have you read the Queue Master document yet?

You can pass a job or job id, or an array of jobs or job ids to the Queue.removeJob method and it will remove them totally from the database.

It is important to note that the returned Promise resolves to an array of job ids even if you only supplied a single job or id.

Examples

This example shows how to remove one job.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const job = q.createJob()
// Decorate your job with job data for processing here

q.addJob(job).then((savedJobs) => {
  // savedJobs is an array of a single job object
  return q.removeJob(savedJobs)
}).then((removedJobIds) => {
  // If you need the removed job id for any reason, here it is
  console.dir(removedJobIds)
}).catch(err => console.error(err))

This example shows how to remove more than one job.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const jobs = [q.createJob(), q.createJob()]
// The jobs array will contain 2 jobs
// Don't forget to decorate your jobs with job data

q.addJob(jobs).then((savedJobs) => {
  // savedJobs is an array of a 2 job objects
  return q.removeJob(savedJobs)
}).then((removedJobIds) => {
  // If you need the removed job ids for any reason, here they are
  console.dir(removedJobIds)
}).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