-
Notifications
You must be signed in to change notification settings - Fork 16
Queue.findJobByName
Parameter: predicate Object or Function
-
predicatecan be a simple object or a complex function. - If a function is passed you are restricted to using RethinkDBs ReQL expressions.
Parameter: raw Boolean
- True to return raw database data rather than a Job object
Returns: Array
- An
Arrayof Job objects or an emptyArray. - If you set
raw, anArrayof generic JavaScript objects.
Example:
q.findJob({ email: '[email protected]' }).then((jobs) => {
// jobs will either be an empty array
// or an array of Job objects that have an
// email property equal to '[email protected]'
}).catch(err => console.error(err))One of the most flexible methods on the Queue objects is the Queue.findJob. This method exposes the full and rich filter functionality of the RethinkDB ReQL (RethinkDB Query Language).
Using the Queue.findJob method you can extract information about the jobs in the queue. Here is a quick list of information you could obtain using Queue.findJob.
- Confirm a job has not already been added to the queue (ensure unique job).
- Get all jobs related to a common task.
- Get all
failedorterminatedjobs. - Produce reports on any job data.
This example shows how to ensure a job has not already been added to the queue before adding it. You will need some unique identification value assigned to the jobs to be able to find them. In this example there is a Job.hash property however you can use any key/value you like. If it is not a unique property then multiple results will be returned.
Warning: The Queue.findJob is a single atomic operation. It is possible for another Queue object to add the job to the queue in between you finding the job and adding the job.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob({ hash: '12345678' }) // Some know hash value
// findJob will return any job that has job.hash === '12345678'
q.findJob({ hash: '12345678' }).then((exists) => {
if (exists.length < 1) {
return q.addJob(job)
}
return
}).catch(err => console.error(err))This example shows how to use a function as the predicate. The function will return all jobs that completed between January 1st, 2012 (included) and January 1st, 2013 (excluded).
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const predicate = function (job) {
return job('dateCompleted').during(
q.r.time(2012, 1, 1, 'Z'), q.r.time(2013, 1, 1, 'Z'))
}
q.findJob(predicate).then((jobs) => {
// Zero or more jobs in an array.
}).catch(err => console.error(err))To really understand how powerful this functionality is please read more on the ReQL filter page.
- 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