Skip to content

Queue.reanimateJob

Grant Carthew edited this page Nov 19, 2016 · 2 revisions

Method Signature

Queue.reanimateJob(JobOrId, dateEnable)

Parameter: JobOrId Object or String or Array

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

Parameter: dateEnable Date Object Optional

  • A future date you want the job to be processed.

Returns: Promise => Array

  • An array of job ids that have been cancelled.

Example:

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

Description

If you find a job has been cancelled or terminated that still needs to be processed, you can call the Queue.reanimateJob method to re-enable the job for processing.

If you would like to delay the job processing until a future date, supply the dateEnable argument with a Date object set to a future date. If you leave the dateEnable argument out of the method call the job will be ready for processing immediately.

Behind the scenes Queue.reanimateJob sets the job progress to zero, the job retryCount to zero, the job status to waiting, and applies the new dateEnable date.

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 reanimate 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.cancelJob(savedJobs)
}).then((cancelledJobIds) => {
  // If you need the cancelled job ids for any reason, here they are
  console.dir(cancelledJobIds)
  return q.reanimateJob(cancelledJobIds[0])
}).then((reanimatedJobIds) => {
  // if you need the reanimated job ids for any reason, here they are
  console.dir(reanimatedJobIds)
}).catch(err => console.error(err))

This example shows how to reanimate 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.cancelJob(savedJobs)
}).then((cancelledJobIds) => {
  // If you need the cancelled job ids for any reason, here they are
  console.dir(cancelledJobIds)
  return q.reanimateJob(cancelledJobIds[0])
}).then((reanimatedJobIds) => {
  // if you need the reanimated job ids for any reason, here they are
  console.dir(reanimatedJobIds)
}).catch(err => console.error(err))

This example shows how to reanimate one job to be processed at a later date.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const processDate = new Date((new Date()).getTime() + 180000) // now + 3 minutes
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.cancelJob(savedJobs)
}).then((cancelledJobIds) => {
  // If you need the cancelled job ids for any reason, here they are
  console.dir(cancelledJobIds)
  return q.reanimateJob(cancelledJobIds[0], processDate)
}).then((reanimatedJobIds) => {
  // if you need the reanimated job ids for any reason, here they are
  console.dir(reanimatedJobIds)
}).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