Skip to content

Queue.getJob

Grant Carthew edited this page Oct 1, 2016 · 7 revisions

Method Signature

Queue.getJob(JobOrId)

Parameter: JobOrId Object or String or Array

  • 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 of jobs even if you only supplied a single job or id.

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(), q.createJob()]
// The jobs array will contain 2 jobs
// Don't forget to decorate your jobs with job data

q.addJob(jobs).then((savedJobs) => {
  // savedJobs is an array of a 2 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