-
Notifications
You must be signed in to change notification settings - Fork 16
Job Editing
One of the most powerful and flexible methods within rethinkdb-job-queue is the Job.update method. It allows you, without restriction, to change any value of a job and save those changes back to the queue database.
This document will give you some examples of how you may use the Job.update method to perform advanced changes to jobs in the queue.
This example will show how to reanimate or re-run a job that has finished. A job is considered finished if it has either a completed, cancelled, or terminated status. See the Job Status document for more detail.
To start with, here is a JSON object representing a cancelled job.
{
q: [Object],
data: 'foo',
dateCreated: 2016-09-19T03:07:44.394Z,
dateEnable: 2016-09-19T03:12:44.451Z,
dateFinished: 2016-09-19T03:07:44.469Z,
dateStarted: 2016-09-19T03:07:44.451Z,
id: '5127d082-fe7e-4e88-b1de-7093029695c3',
log:
[ { date: 2016-09-19T03:07:44.421Z,
message: 'Job added to the queue',
queueId: 'WebDev::rjqJobQueueTestJobs:1942:ebc89e54-f7d3-40a1-952a-3bb152d154ce',
retryCount: 0,
status: 'waiting',
type: 'information' },
{ date: 2016-09-19T03:07:44.451Z,
message: 'Job retrieved and active',
queueId: 'WebDev::rjqJobQueueTestJobs:1942:ebc89e54-f7d3-40a1-952a-3bb152d154ce',
retryCount: 0,
status: 'active',
type: 'information' },
{ date: 2016-09-19T03:07:44.470Z,
message: 'The quick brown fox jumped over the lazy dog',
queueId: 'WebDev::rjqJobQueueTestJobs:1942:ebc89e54-f7d3-40a1-952a-3bb152d154ce',
retryCount: 0,
status: 'cancelled',
type: 'information' } ],
priority: 'normal',
progress: 0,
queueId: 'WebDev::rjqJobQueueTestJobs:1942:ebc89e54-f7d3-40a1-952a-3bb152d154ce',
retryCount: 0,
retryDelay: 600000,
retryMax: 3,
status: 'cancelled',
timeout: 300000
}To re-run this job you will need to change three properties as follows.
- Status: Change the status from
cancelledtowaiting. - retryCount: Set the
retryCountto zero if it is not alreay zero. - dateEnable: Set the
dateEnableto now or a future date.
Here is the code to make these changes. The assumption is that the job is already in the database with the properties above. All we need to do it get the job and update its properties.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
q.getJob('5127d082-fe7e-4e88-b1de-7093029695c3').then((savedJobs) => {
savedJobs[0].status = 'waiting'
savedJobs[0].retryCount = 0
savedJobs[0].dateEnable = new Date()
return savedJobs[0].update('Job reanimated')
}).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