Skip to content

Job Options

Grant Carthew edited this page Feb 10, 2017 · 30 revisions

Description

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.

How to change Job options?

There are four ways to set or change the job options.

See the linked documents above for more detail. The example below shows how to use each option.

Changing Job Options Example

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

Job name Option

Default: uuid copied from the Job.id

Valid: Any string value.

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.

name Example

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

Job priority Option

Default: normal

Valid: See the table below.

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.

priority Example

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

Job timeout Option

Default: 300000 milliseconds (5 minutes)

Valid: Any positive integer. Make it as high as possible.

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.

timeout Example

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

Job retryMax Option

Default: 3

Valid: 0 to disable. Any positive integer.

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.

retryMax Example

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

Job retryDelay Option

Default: 600000 milliseconds (10 minutes)

Valid: 0 to disable. Any positive integer.

The retryDelay option allows you to progressively delay the job processing on successive retries.

See the Job Retry document for more detail.

retryDelay Example

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

Job repeat Option

Default: false

Valid: false to disable. Any positive integer. true for continuous.

The repeat option allows you to repeat processing of a job.

See the Job Repeat document for more detail.

repeat Example

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

Job repeatDelay Option

Default: 300000 ms (5 min)

Valid: Any positive integer. Setting this value too low will cause excessive load.

The repeatDelay option allows you to delay repeat processing of a job.

See the Job Repeat document for more detail.

repeatDelay Example

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

Job dateEnable Option

Default: new Date() Current date and time

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.

dateEnable Example

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

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally