🚨 Announcing Vendure v2 Beta

Job

Job

Package: @vendure/core File: job.ts

A Job represents a piece of work to be run in the background, i.e. outside the request-response cycle. It is intended to be used for long-running work triggered by API requests. Jobs should now generally be directly instantiated. Rather, the JobQueue add() method should be used to create and add a new Job to a queue.

Signature

class Job<T extends JobData<T> = any> {
  readonly readonly id: number | string | null;
  readonly readonly queueName: string;
  readonly readonly retries: number;
  readonly readonly createdAt: Date;
  name: string
  data: T
  state: JobState
  progress: number
  result: any
  error: any
  isSettled: boolean
  startedAt: Date | undefined
  settledAt: Date | undefined
  duration: number
  attempts: number
  constructor(config: JobConfig<T>)
  start() => ;
  setProgress(percent: number) => ;
  complete(result?: any) => ;
  fail(err?: any) => ;
  cancel() => ;
  defer() => ;
  on(eventType: JobEventType, listener: JobEventListener<T>) => ;
  off(eventType: JobEventType, listener: JobEventListener<T>) => ;
}

Members

id

readonly property
type:
number | string | null

queueName

readonly property
type:
string

retries

readonly property
type:
number

createdAt

readonly property
type:
Date

name

property
type:
string

data

property
type:
T

state

property
type:
JobState

progress

property
type:
number

result

property
type:
any

error

property
type:
any

isSettled

property
type:
boolean

startedAt

property
type:
Date | undefined

settledAt

property
type:
Date | undefined

duration

property
type:
number

attempts

property
type:
number

constructor

method
type:
(config: JobConfig<T>) => Job

start

method
type:
() =>
Calling this signifies that the job work has started. This method should be called in the JobQueueStrategy next() method.

setProgress

method
type:
(percent: number) =>
Sets the progress (0 - 100) of the job.

complete

method
type:
(result?: any) =>
Calling this method signifies that the job succeeded. The result will be stored in the Job.result property.

fail

method
type:
(err?: any) =>
Calling this method signifies that the job failed.

cancel

method
type:
() =>

defer

method
type:
() =>
Sets a RUNNING job back to PENDING. Should be used when the JobQueue is being destroyed before the job has been completed.

on

method
type:
(eventType: JobEventType, listener: JobEventListener<T>) =>
Used to register event handlers for job events

off

method
type:
(eventType: JobEventType, listener: JobEventListener<T>) =>

JobEventType

Package: @vendure/core File: job.ts

An event raised by a Job.

Signature

type JobEventType = 'progress'

JobEventListener

Package: @vendure/core File: job.ts

The signature of the event handler expected by the Job.on() method.

Signature

type JobEventListener<T extends JobData<T>> = (job: Job<T>) => void