-
Notifications
You must be signed in to change notification settings - Fork 16
Job Processing
Grant Carthew edited this page Feb 7, 2017
·
7 revisions
To process jobs within rethinkdb-job-queue
you need to supply a handler function to Queue.process.
This handler function should look something like this:
const worldPeace = require('world-peace')
function saveTheWorld (job, next, onCancel) {
// job will hold the values you need to process the job.
worldPeace.addSuperHero(job.hero)
// onCancel will be called by the Queue object if the job
// is cancelled in the queue.
onCancel(job, () => {
// Gracefully cancel your job.
return worldPeace.cancel()
})
worldPeace.process().then((success) => {
// If the job processing succeeds, call next with the results.
// Pass null for the error.
return next(null, success)
}).catch((err) => {
// If the job processing fails, call next with an error.
return next(err)
})
}
To make use of the above handler function you need to add it to the Queue object as follows:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
q.process(saveTheWorld)
Now the Queue object is ready to process jobs. Simply add a job to the queue:
let job = q.createJob({ hero: 'Spider-Man' })
q.addJob(job).catch(err => console.error(err))
The Queue object will now retrieve the job from the database and process it. If all goes well there will be world peace.
- 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