Skip to content

Queue.getJob

Grant Carthew edited this page Aug 18, 2016 · 7 revisions

Method Signature

Queue.getJob(JobOrId)

Parameter: JobOrId Object or String

  • A single Job or Id, or an array of Jobs or Ids.

Returns: Promise => Array

  • An array of one or more Job objects.

Example:

q.getJob(jobs).then((savedJobs) => {
  // savedJobs is an array of one or more Jobs
}).catch((err) => {
  console.error(err)
})

Description

At any time and for any reason you may want to retrieve the details of a job in the queue. This is the API for you.

Simply call Queue.getJob passing in a single or array of jobs or job ids.

It is important to note that the returned Promise resolves to an array or jobs event if you only supplied a single job or id. If only a single job or id is supplied to Queue.getJob then the returned array will only contain one job.

Examples

This example shows how to get the details for one job.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const job = q.createJob()
// Decorate your job with job data for processing here

q.addJob(job).then((savedJobs) => {
  // savedJobs is an array of a single job object
  return q.getJob(savedJobs)
}).then((retrievedJobs) => {
  // Use the retrievedJobs array to get what you need.
  console.dir(retrievedJobs[0].log)
}).catch((err) => {
  console.error(err)
})

This example shows how to get the details for more than one job.

const Queue = require('rethinkdb-job-queue')
const q = new Queue()
const jobs = q.createJob(10)
// The jobs array will contain 10 jobs
// Decorate your jobs with job data for processing here

q.addJob(jobs).then((savedJobs) => {
  // savedJobs is an array of a 10 job objects
  return q.getJob(savedJobs)
}).then((retrievedJobs) => {
  // Use the retrievedJobs array to get what you need.
  retrievedJobs.map((singleJob) => {
    console.dir(singleJob.log)
  })
}).catch((err) => {
  console.error(err)
})

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally