-
Notifications
You must be signed in to change notification settings - Fork 16
Queue Options
When creating the Queue object you can supply options to customize the way the queue works. Each one of the Queue object options is discussed below.
Option | Type | Default |
---|---|---|
host | String | localhost |
port | Integer | 28015 |
db | String | rjqJobQueue |
name | String | rjqJobList |
masterInterval | Integer |
310 seconds |
changeFeed | Boolean | true |
concurrency | Integer | 1 |
removeFinishedJobs | Bool / Int |
180 days |
This example is to show all the options being customized:
const Queue = require('rethinkdb-job-queue')
const options = {
host: 'proddb.domain.com',
port: 10000,
db: 'JobQueue',
name: 'VideoProcess',
masterInterval: 1000,
changeFeed: true,
concurrency: 50,
removeFinishedJobs: false
}
const q = new Queue(options)
The host
option can be ignored if you are running RethinkDB on the same machine as the nodejs service. If not, point the queue to the server you have RethinkDB running on.
This example points the Queue object at an IP address:
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ host: '192.168.1.10' })
This example points the Queue object at a DNS name:
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ host: 'proddb.domain.com' })
The port
option allows you to specify the TCP port used by the RethinkDB database.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ port: 8000 })
Set the db
option to be the name of your job database in RethinkDB. The db
option will either create a new database if it does not exist, or use an existing database. If you would like your existing database to hold your job Tables, simply set the db
option to the existing name you are using in RethinkDB.
Important: There is no API call in rethinkdb-job-queue
that can drop the database. The Queue.drop method only drops the queue Table in the database, not the database itself.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ db: 'JobQueue' })
The name
option defines the name of the Queue, the Queue object, and the Table created in RethinkDB. You can create multiple Queue objects with different names causing multiple Tables to be created in the RethinkDB database.
Important: It is highly recommended not to set the name
option to the same name of an existing table in your database. The Queue.drop API call will drop the Table from the database. Always use a name related to the jobs you are processing.
This example creates two queues using the default options except for the name
. One of the queues is called 'registration' and the other 'video'. This example will create two Tables in the RethinkDB database called 'registration' and 'video'.
const Queue = require('rethinkdb-job-queue')
const regoQ = new Queue({ name: 'registration' })
const videoProcessQ = new Queue({ name: 'video' })
The masterInterval
option determines how often the Queue Master review process is carried out against the queue.
Please refer to the Queue Master document for more detail.
The default value of 310
seconds was chosen because it is 10 seconds past the job timeout
default value of 300
seconds. This is to improve detection of failed nodejs processes on queue startup.
Warning: Setting the masterInterval
value too low will cause excessive database load. Every time this period lapses queries are run against the database. Keep this value as high as possible.
This example shows setting the masterInterval
to one minute to ensure the queue is kept clean and failed jobs get processed.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ masterInterval: 60 })
If enabled the changeFeed
option will cause the Queue object to raise events for the entire queue rather than just the local Queue object.
Behind the scenes a RethinkDB change feed is created for the whole of the queue Table in the database. Once the changes are received by the Queue object, they are checked to ensure they are not local changes. If the changes are detected as local changes (a change made by self) they are ignored because the events will be raised by the Queue object. If the changes are not local then the relevant event is raised.
See the Queue Events document for more detail.
This example simply disables the changeFeed
option.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ changeFeed: false })
The Queue object can process many jobs at once. Keep in mind the blocking nature of long running tasks. If your jobs are external and will not block the node process, feel free to push the concurrency value through the roof.
This example sets the concurrency
option to 100. If more than 100 jobs are available on the queue then 100 will be processed at once.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ concurrency: 100 })
The removeFinishedJobs
option is used to control how the queue removes jobs which are considered to be finished from the database.
A job is considered finished when it has a status of either completed
, cancelled
, or terminated
. See the Job Status document for more detail.
Finished jobs will be permanently removed from the database based on the values you assign to removeFinishedJobs
.
This is one of the more flexible options available on Queue objects. You have three values you can assign to the removeFinishedJobs
option.
Setting the removeFinishedJobs
option to true
will cause jobs to be removed from the queue immediately when they are finished. They will no longer be in the database.
Setting the removeFinishedJobs
option to false
or 0
will prevent the queue from ever removing jobs from the database.
By setting the removeFinishedJobs
option to a number such as 180
, the Queue Master review process will permanently remove jobs that were finished 180
days ago.
This example shows setting removeFinishedJobs
option to false
causing the queue to never remove jobs from the database:
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ removeFinishedJobs: false })
This example shows setting the removeFinishedJobs
option to 30
days. The Queue Master review process will remove finished jobs when they are a month old.
const Queue = require('rethinkdb-job-queue')
const q = new Queue({ removeFinishedJobs: 30 })
- Introduction
- Tutorial
- Queue Constructor
- Queue Connection
- Queue Options
- Queue PubSub
- Queue Master
- Queue Events
- State Document
- Job Processing
- Job Options
- Job Status
- Job Retry
- Job Repeat
- Job Logging
- Job Editing
- Job Schema
- Job Name
- Complex Job
- Delayed Job
- Cancel Job
- Error Handling
- Queue.createJob
- Queue.addJob
- Queue.getJob
- Queue.findJob
- Queue.findJobByName
- Queue.containsJobByName
- Queue.cancelJob
- Queue.reanimateJob
- Queue.removeJob
- Queue.process
- Queue.review
- Queue.summary
- Queue.ready
- Queue.pause
- Queue.resume
- Queue.reset
- Queue.stop
- Queue.drop
- Queue.Job
- Queue.host
- Queue.port
- Queue.db
- Queue.name
- Queue.r
- Queue.id
- Queue.jobOptions [R/W]
- Queue.changeFeed
- Queue.master
- Queue.masterInterval
- Queue.removeFinishedJobs
- Queue.running
- Queue.concurrency [R/W]
- Queue.paused
- Queue.idle
- Event.ready
- Event.added
- Event.updated
- Event.active
- Event.processing
- Event.progress
- Event.log
- Event.pausing
- Event.paused
- Event.resumed
- Event.completed
- Event.cancelled
- Event.failed
- Event.terminated
- Event.reanimated
- Event.removed
- Event.idle
- Event.reset
- Event.error
- Event.reviewed
- Event.detached
- Event.stopping
- Event.stopped
- Event.dropped
- Job.setName
- Job.setPriority
- Job.setTimeout
- Job.setDateEnable
- Job.setRetryMax
- Job.setRetryDelay
- Job.setRepeat
- Job.setRepeatDelay
- Job.updateProgress
- Job.update
- Job.getCleanCopy
- Job.addLog
- Job.getLastLog