-
Notifications
You must be signed in to change notification settings - Fork 16
Queue.findJobByName
Parameter: name
String
-
name
can be any string value.
Parameter: raw
Boolean
- True to return raw database data rather than a Job object
Returns: Promise
=> Array
- An
Array
of Job objects or an emptyArray
. - If you set
raw
, anArray
of generic JavaScript objects.
Example:
q.findJobByName('superman').then((jobs) => {
// jobs will either be an empty array
// or an array of Job objects that have an
// name property equal to 'superman'
}).catch(err => console.error(err))
To find generic jobs within the queue you can use the Queue.findJob method. It has one major drawback though, it doesn't use database indexes. This is why the Job.name property and Job.setName methods were added to rethinkdb-job-queue
in v2.3.0.
When you assign names to jobs you give yourself a fast method of being able to retrieve those jobs based on a custom string value. By calling Queue.findJobByName
you are searching the jobs in your queue table using a database index. This makes Queue.findJobByName
very fast with minimum load placed on the RethinkDB database.
Warning: All jobs with the same name
value will be returned by the Queue.findJobByName
method. This means you may get either an empty array []
, an array with one job [job]
, or an array with many jobs, [job1, job2, job3]
.
If you are after a unique signature for your jobs, use the automatically generated Job.id. Ids are guaranteed to be unique.
This example creates a job with a name
value of 'superman'. It then finds that job.
const Queue = require('rethinkdb-job-queue')
const q = new Queue()
let job = q.createJob().setName('superman')
// job.name === 'superman'
// findJobByName will return any job that has job.name === 'superman'
q.findJobByName('superman').then((supermen) => {
if (supermen.length === 1) {
// Do something with superman
} else {
// Is this an error?
}
}).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