-
Notifications
You must be signed in to change notification settings - Fork 16
Job Repeat
If you have a task that needs to be processed repeatedly on a specific schedule there are a number of packages on NPM you can use to help you achieve this. However, if you need a job to repeat with a simple delay between each run, rethinkdb-job-queue
can do this for you.
When you create a Job object you can set the repeat and the repeatDelay options. These allow you to repeat the processing of jobs either for a fixed number of times or continuously.
By setting the repeat
option to true
the job will continually repeat after waiting for the repeatDelay
time period. Alternatively, you can set the repeat
option to a number and the job will be processed and then repeated the correct number of times.
If a job fails processing and has the retry options enabled, the job will follow the normal retry procedure. If the retries fail instead of transitioning to a terminated
status, the job goes into a waiting
status and the retryDelay
will apply.
Note: If the queue is not working hard the repeated processing of jobs will require the Queue Master review process to begin processing the job after the Job.repeatDelay time period.
Note: Consider setting the Queue option limitJobLogs to a smaller number than the default 1000
log entries.
Warning: Do not set the retryDelay value too low unless the repeated job takes a long time to run. Judge the delay time related to the task as hand.
The following example will repeat every minute with the assumption the job only take a few milliseconds to complete.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setRepeat(true).setRepeatDelay(60000)
q.addJob(job).catch(err => console.error(err))
q.process((job, next, onCancel) => {
// Process the job calling next on success.
next(null, 'Yip yar!')
})
This example will process the job a total of 3 times by setting the repeat option to 2. The job will be processed once and then repeated twice.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setRepeat(2)
q.addJob(job).catch(err => console.error(err))
q.process((job, next, onCancel) => {
// Process the job calling next on success.
next(null, 'Yip yar!')
})
- 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