-
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.
If for some reason you need to change the data associated with a job you can do so with the following code. For this example we need to change the job.data
property from foo
to bar
.
Assumptions:
- The job is in the queue.
- The job has not been processed.
- The
job.data
property is set tofoo
. - We have the job id.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
q.getJob('5127d082-fe7e-4e88-b1de-7093029695c3').then((savedJobs) => {
savedJobs[0].data = 'bar'
return savedJobs[0].update()
}).catch(err => console.error(err))
If for some reason you had extra data saved with a job and you need it removed for some security reason. You could do so easily enough as this example shows.
Assumptions:
- The job is in the queue.
- The
job.secret
property is set. - We have the job id.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
q.getJob('5127d082-fe7e-4e88-b1de-7093029695c3').then((savedJobs) => {
delete savedJobs[0].secret
return savedJobs[0].update()
}).catch(err => console.error(err))
If you had a job waiting for processing and you need to disable the job until further notice, here is one way you could achieve this.
Assumptions:
- The job is in the queue.
- The job has not been processed.
- We have the job id.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
q.getJob('5127d082-fe7e-4e88-b1de-7093029695c3').then((savedJobs) => {
delete savedJobs[0].status = 'disabled'
return savedJobs[0].update()
}).catch(err => console.error(err))
The example above is setting the Job.status property to disabled
which is an invalid status. See the Job Status document for a list of the status values that are valid. By setting the status to an invalid value, the internal getNextJob()
method will not retrieve the job; hence it is disabled.
It may be interesting to note that the Queue.summary method will return a list of status values now including disabled
.
Note: The getNextJob()
internal method uses an index which returns only jobs with a waiting
or failed
status.
Other ways you could disable a job would be to set the dateEnable
property to some ridiculous time in the future, say 200 years.
- 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