Skip to content

Queue Events

Grant Carthew edited this page Nov 21, 2016 · 8 revisions

Description

The rethinkdb-job-queue Queue object supports raising Node.js Events. For a full list of supported events use the menu on the right or see the Queue API document.

Depending on the changeFeed Queue option, the events will either be local to the Queue object, or global for the whole queue.

With this in mind, if you are not interested in events from other worker Queue objects, when you create your local Queue object make sure you set the changeFeed option to false.

Examples

All of the following examples use only the completed event. Again, for a full list of supported events use the menu on the right or see the Queue API document.

Note: These examples are not full examples because they do not include the code to create a job and add it to the queue.

Local Event

This example will raise the completed event when a job is completed for the local Queue object only.

const Queue = require('rethinkdb-job-queue')

const qOptions = {
  changeFeed: false
}

const q = new Queue(null, qOptions)

q.on('completed', (queueId, jobId, isRepeating) => {
  console.log('Job completed: ' + jobId)
})

Global Event

This example will raise the completed event when any job in the queue is completed. This includes jobs processed by the local Queue object or any other Queue object on the same machine or distributed across multiple machines.

const Queue = require('rethinkdb-job-queue')

const qOptions = {
  changeFeed: true // This is the default and is not required
}

const q = new Queue(null, qOptions)

q.on('completed', (queueId, jobId, isRepeating) => {
  console.log('Job completed: ' + jobId)
})

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally