-
Notifications
You must be signed in to change notification settings - Fork 16
Job Options
To process anything using rethinkdb-job-queue you need to create Job objects. These Job objects are created by using Queue.createJob. When a job is created there are four options available for you to customize how the job is processed within the queue.
The priority option allows you to control the order of processing for the jobs in the queue.
There are seven priority values as follows:
| Name | Number | Description |
|---|---|---|
| lowest | 60 | The last jobs to get processed |
| low | 50 | Not as important and a typical job |
| normal | 40 | The default job priority |
| medium | 30 | For more important jobs |
| high | 20 | Need to be processed first |
| highest | 10 | These jobs will be processed before all others |
The Number column in the table above is showing the value that gets stored in the database for a specific priority. Jobs within your code have the Name values above. These names get converted to numbers on adding the job to the queue. Names are used within your code purely for readability.
A higher priority job will always get processed by the queue before the lower priority jobs. As an example, if you have 100 'normal' priority jobs, and you add a 'medium' priority job to the queue, the 'medium' priority job will be the next job to get processed.
The below example simply creates a high priority job:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
priority: 'high'
}
let job = q.createJob(options)
// Now add the job to the QueueThe job timeout option is for defining the maximum time a job should be processed for before getting classed as failed.
There are two ways a job will be considered a failed job; if the nodejs process takes too long and runs past the timeout value, or if the nodejs process hangs or crashes.
The timeout option is involved in this process and is discussed in greater depth in the Job Retry document.
The below example sets the timeout value to 600 seconds (ten minutes).
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
timeout: 600
}
let job = q.createJob(options)
// Now add the job to the QueueIf the retryMax value of a job is greater than zero, then it will be retried if the job processing fails. See Job Retry for more details.
Setting the retryMax value to 0 will disable retries.
Setting the retryMax value to 1 will mean the job will get processed twice. Once for the first try, which is not a retry. Once for the retry.
Setting the retryMax option to 6 will mean the job will get processed seven times. As above, once for the first try, then six retries.
Once a job has been retried upto the maximum value set by retryMax, the job status will be changed to terminated and the job will get no more attention from the queue.
The below example sets the retryMax to only one retry:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
retryMax: 1
}
let job = q.createJob(options)
// Now add the job to the QueueThe retryDelay option allows you to progressively delay the job processing on successive retries.
See the Job Retry document for more details.
The below example sets the retryDelay value to 1000 seconds:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
retryDelay: 1000
}
let job = q.createJob(options)
// Now add the job to the QueueThis example is to show all the options being customized:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
priority: 'low',
timeout: 200,
retryMax: 2,
retryDelay: 0
}
let job = q.createJob(options)
// Now add the job to the Queue- 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