Skip to content

Delayed Job

Grant Carthew edited this page Sep 9, 2016 · 17 revisions

What is dateEnable?

One of the extremely important properties of the rethinkdb-job-queue Job objects is the dateEnable property. Every job in the queue will have a dateEnable property and it will be populated with a date.

When the Queue object is processing jobs in the queue backing Table it runs an internal function called getNextJob(). This function queries the RethinkDB database for jobs that need processing. If the dateEnable property of a job in the queue has a date that is set to some time in the future, the job will not be retrieved.

This gives us the flexibility to be able to set the date and time we want the job to be processed prior to adding the job to the queue.

Warning: Jobs that are delayed in a relative inactive queue will only be processed at the Queue Master review time interval. Because of this your delayed jobs will only run after the dateEnable date and on the next Queue Master review process. This will not be an issue if the queue is very busy. Please read the Queue Master document for a better understanding of this process.

Examples

Without a custom dateEnable value

This example is to show you what a job looks like without changing any properties of the job.

Firstly we need to create a job and add it to the queue.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob()
job.data = 'foo'
q.addJob(job).catch((err) => {
  console.error(err)
})

The above code will add a job to the queue without changing any of the jobs properties.

Here is the job data that is stored in the queue database.

{
  "dateCreated": Sat Aug 20 2016 21:26:32 GMT+00:00 ,
  "dateEnable": Sat Aug 20 2016 21:26:32 GMT+00:00 ,
  "data": "foo",
  "id":  "2250b4fc-5167-49ae-a139-eff48b7b1580" ,
  "log": [{
    "date": Sat Aug 20 2016 21:27:03 GMT+00:00 ,
    "message":  "Job added to the queue" ,
    "queueId":  "WebDev:rjqJobQueue:rjqJobList:18532:93ea5586-f840-4b03-9acc-ef3fc9260858" ,
    "retryCount": 0 ,
    "status":  "added" ,
    "type":  "information"
  }] ,
  "priority": 40 ,
  "progress": 0 ,
  "queueId":  "WebDev:rjqJobQueue:rjqJobList:18532:93ea5586-f840-4b03-9acc-ef3fc9260858" ,
  "retryCount": 0 ,
  "retryDelay": 600 ,
  "retryMax": 3 ,
  "status":  "added" ,
  "timeout": 300
}

With the above job you will notice the job has a dateEnable property that is set to the same value as the dateCreated property. This is due to the Job object constructor that sets

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally