Skip to content

Queue Constructor

Grant Carthew edited this page Sep 14, 2016 · 7 revisions

Description

The primary JavaScript object you use with rethinkdb-job-queue is the Queue object. The Queue object connects to the RethinkDB database. If the database does not exist it will be created. Within the database there will be a table with the same name as the Queue name. Again, if the table does not exist it will be created.

The constructor for the Queue object takes two arguments being the Connection Options object and the Queue Options object. The Connection and Queue options are not required and if not supplied the default values will apply.

See the Connection Options and Queue Options documents for more detail about what the options are. This document is to show you how to create the Queue object with these options.

Constructor Options
Default Options
Connection Options
Connection Driver
Queue Options
Connection and Queue Options

Default Options

To use all the default options when creating the Queue object use the following instantiation code.

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

See the Connection Options and Queue Options documents for information about what the default values are.

Connection Options

To allow the Queue object to manage the RethinDB driver called rethinkdbdash simply pass the connection options to the Queue constructor as the first argument.

This example will connect to a RethinkDB instance running on host 'db01.domain.com' at port '12345'. If the database called 'JobQueue' does not exist it will create it.

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

const cxnOptions = {
  host: 'db01.domain.com',
  port: 12345,
  db: 'JobQueue'
}

const q = new Queue(cxnOptions)

Connection Driver

If you would prefer to manage the rethinkdbdash driver object yourself you can pass it as the first argument.

This example will connect to a RethinkDB instance running on host 'db01.domain.com' at the default port. It will create a database called 'JobQueue' if it does not exist.

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

const db01driver = rethinkdbdash({ host: 'db01.domain.com', db: 'JobQueue' })

const q = new Queue(db01driver)

Queue Options

If you are happy to connect to the default database name 'rjqJobQueue' on the 'localhost' at port 28015 but would like to change the Queue options, use the following instantiation code.

This example only changes the queue name and changeFeed options. It will create a table in the default database called 'RegistrationJobs' and disable global events.

const rethinkdbdash = require('rethinkdbdash')

const qOptions = {
  name: 'RegistrationJobs',
  changeFeed: false
}

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally