-
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 five options available for you to customize how the job is processed within the queue.
Option | Type | Default |
---|---|---|
name | String |
uuid same as the Job id |
priority | String | normal |
timeout | Integer |
300000 ms (5 min) |
retryMax | Integer | 3 |
retryDelay | Integer |
600000 ms (10 min) |
repeat | Bool/Int | false |
repeatDelay | Integer |
300000 ms (5 min) |
dateEnable | Date | new Date() |
You can change the job option default values for the Queue object, meaning you do not need to customize each job. See the Queue.jobOptions document for more detail.
There are four ways to set or change the job options.
- Set the default options using the Queue.jobOptions property.
- Supply options with the data when calling the Queue.createJob method.
- Use the fluent API on a Job object. Fluent APIs are;
- Job.setName
- Job.setPriority
- Job.setTimeout
- Job.setRetryMax
- Job.setRetryDelay
- Job.setDateEnable
- Set the property directly on the job
See the linked documents above for more detail. The example below shows how to use each option.
This example shows all the options being customized using the four methods described above.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
// Change the default options for every new job.
q.jobOptions = {
name: 'Unique or Group Name',
priority: 'low',
timeout: 200,
retryMax: 2,
retryDelay: 0,
dateEnable: new Date + 1000000
}
// Create the job and set the 'priority' to 'low' in the job data options.
// We also set the 'timeout' option to 10 seconds using the fluent API.
let job = q.createJob({ priority: 'low' }).setTimeout(10000)
// Here we change the 'retryMax' to 4.
job.retryMax = 4
// The job object will have these options values.
// name = 'Unique or Group Name'
// priority = 'low'
// timeout = 10000
// retryMax = 4
// retryDelay = 0
// dateEnable = new Date() + 1000000
// Now add the job to the Queue
Default: uuid
copied from the Job.id
You can use the name
job property to group jobs or identify jobs.
Warning: Setting the job name
is not guaranteed to be unique. Use the Job.id for unique identification.
The benefit of the name
property is that it is backed by an index within the database. This makes finding named jobs and testing job existence faster with less load on the database.
The below example simply creates a named job for the user 'Batman':
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setName('Batman')
// Now add the job to 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 as 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()
let job = q.createJob().setPriority('high')
// Now add the job to the Queue
The job timeout
option is for defining the maximum time a job should be processed for before getting classified as failed.
There are two ways a job will be considered a failed job using this timeout
option; if the Queue object job processing 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.
See Job.progress for details on how you can control this timeout whilst a job is being processed.
The below example sets the timeout
value to 600000 milliseconds (10 minutes).
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setTimeout(600000)
// Now add the job to the Queue
If 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 detail.
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()
let job = q.createJob().setRetryMax(1)
// Now add the job to the Queue
The retryDelay
option allows you to progressively delay the job processing on successive retries.
See the Job Retry document for more detail.
The below example sets the retryDelay
value to 1000000 milliseconds (~17 min):
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setRetryDelay(1000000)
// Now add the job to the Queue
The repeat
option allows you to repeat processing of a job.
See the Job Repeat document for more detail.
The below example sets the repeat
value to 3. This will cause the job to be processed a total of 4 times; once for the original processing with three repeats:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setRepeat(3)
// Now add the job to the Queue
The repeatDelay
option allows you to delay repeat processing of a job.
See the Job Repeat document for more detail.
The below example sets the repeat
value to 3 and updates the repeatDelay
to 24 hours. This will cause the job to be processed a total of 4 times; once for the original processing with three repeats with a 24 hour delay between:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setRepeat(3).setRepeatDelay(86400000)
// Now add the job to the Queue
Valid: Any date. The job will be processed only after the current date is past the dateEnable
value.
You don't need to change this option if you are happy for the job to be processed as soon as possible. If you wish to delay the job processing until a future date, change this option.
See the Delayed Job document for more detail.
The below example sets the dateEnable
value to now plus 1000000 milliseconds:
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setDateEnable(new Date() + 1000000)
// 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