-
Notifications
You must be signed in to change notification settings - Fork 16
Queue.addJob
Parameter: Job
- A single Job object or an Array of Job objects from Queue.createJob.
Returns: Promise
=> Array
- An array of one or more Job objects.
Example:
q.addJob(jobs).then((savedJobs) => {
// savedJobs is an array of one or more Jobs
}).catch(err => console.error(err))
To use rethinkdb-job-queue
you need to add Job objects to the Queue. Job objects can be created by using the Queue.createJob method.
After calling Queue.createJob you will have a valid Job object which is only stored in local memory. This Job object can now be populated with any data you will need to carry out the task of the job.
At this point in time, the Job is not in the Queue and will not be processed. Calling Queue.addJob(job)
will save the job into the backing database table and expose the job to any node available to process it.
Why separate Queue.createJob and Queue.addJob?
To reduce database touch points the createJob
Queue method only creates Job objects locally. If you do not add the Job objects to the Queue by calling addJob
they will never be saved into the backing database and will never be processed.
This allows you to create large numbers of jobs without causing inserts into the database. Once you have configured the multiple jobs with the job data, simply add all the jobs to the Queue at once. By passing an array of jobs to Queue.addJob(jobs)
they will all be saved to the database with one insert.
Note: The example below does not include Queue.process so the jobs will be committed to the database successfully however they will never be processed.
This example creates 100 Job objects and adds them to the Queue with one call to Queue.addJob(jobs)
.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const options = {
priority: 'highest',
retryMax: 2
}
const root = '\mnt\Store\ProcessFile'
const jobs = []
for (let i = 0; i < 100; i++) {
jobs.push(q.createJob({ path: root + i })
.setPriority('highest')
.setRetryMax(2))
}
// jobs is an array of 100 Job objects
// This is the only time the database is touched inserting 100 jobs
q.addJob(jobs).then((savedJobs) => {
// savedJobs is an array of valid Job objects
console.dir(savedJobs[0].path) // Logs { path: '\mnt\Store\ProcessFile0' }
}).catch(err => console.error(err))
- 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