Skip to content

Job Options

Grant Carthew edited this page Aug 14, 2016 · 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 four options available for you to customize how the job is processed within the queue.

Job Priority Option

Default value: 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 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.

priority Example

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 Queue

Job Timeout Option

Default value: 300 seconds (five 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 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.

timeout Example

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 Queue

Job retryMax Option

Default value: 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 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.

retryMax Example

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 Queue

Job retryDelay Option

Default value: 600 seconds (ten 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 details.

retryDelay Example

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 Queue

All Options Example

This 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

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally