Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Job<DATA>

Type parameters

  • DATA = unknown | void

Hierarchy

  • Job

Index

Constructors

constructor

  • new Job(agenda: Agenda, args: Partial<IJobParameters<void>> & { name: string; type: "normal" | "single" }, byJobProcessor?: any): Job
  • new Job(agenda: Agenda, args: Partial<IJobParameters<DATA>> & { data: DATA; name: string; type: "normal" | "single" }, byJobProcessor?: any): Job
  • creates a new job object

    Parameters

    • agenda: Agenda
    • args: Partial<IJobParameters<void>> & { name: string; type: "normal" | "single" }
    • Optional byJobProcessor: any

    Returns Job

  • creates a new job object

    Parameters

    • agenda: Agenda
    • args: Partial<IJobParameters<DATA>> & { data: DATA; name: string; type: "normal" | "single" }
    • Optional byJobProcessor: any

    Returns Job

Properties

Readonly agenda

agenda: Agenda

Readonly attrs

attrs: IJobParameters<DATA>

Private Readonly byJobProcessor

byJobProcessor: boolean

canceled

canceled: Error | undefined

this flag is set to true, if a job got canceled (e.g. due to a timeout or other exception), you can use it for long running tasks to periodically check if canceled is true, also touch will check if and throws that the job got canceled

Methods

Private computeNextRunAt

  • computeNextRunAt(): this

disable

  • disable(): this
  • Prevents the job from running

    Returns this

enable

  • enable(): this

fail

  • fail(reason: Error | string): this
  • Fails the job with a reason (error) specified

    Parameters

    • reason: Error | string

    Returns this

Private fetchStatus

  • fetchStatus(): Promise<void>

isDead

  • isDead(): Promise<boolean>

Private isPromise

  • isPromise(value: unknown): value is Promise<void>
  • Parameters

    • value: unknown

    Returns value is Promise<void>

isRunning

  • isRunning(): Promise<boolean>
  • A job is running if: (lastRunAt exists AND lastFinishedAt does not exist) OR (lastRunAt exists AND lastFinishedAt exists but the lastRunAt is newer [in time] than lastFinishedAt)

    Returns Promise<boolean>

    Whether or not job is running at the moment (true for running)

priority

  • Sets priority of the job

    Parameters

    • priority: JobPriority

      priority of when job should be queued

    Returns this

remove

  • remove(): Promise<number>
  • Remove the job from database

    Returns Promise<number>

repeatAt

  • repeatAt(time: string): this
  • Sets a job to repeat at a specific time

    Parameters

    • time: string

    Returns this

repeatEvery

  • repeatEvery(interval: string | number, options?: { skipImmediate?: undefined | false | true; timezone?: undefined | string }): this
  • Sets a job to repeat every X amount of time

    Parameters

    • interval: string | number
    • Default value options: { skipImmediate?: undefined | false | true; timezone?: undefined | string } = {}
      • Optional skipImmediate?: undefined | false | true
      • Optional timezone?: undefined | string

    Returns this

run

  • run(): Promise<void>

save

  • save(): Promise<Job>

schedule

  • schedule(time: string | Date): this
  • Schedules a job to run at specified time

    Parameters

    • time: string | Date

    Returns this

toJson

touch

  • touch(progress?: undefined | number): Promise<void>
  • Updates "lockedAt" time so the job does not get picked up again

    Parameters

    • Optional progress: undefined | number

      0 to 100

    Returns Promise<void>

unique

  • unique(unique: Required<IJobParameters<DATA>>["unique"], opts?: IJobParameters["uniqueOpts"]): this
  • Data to ensure is unique for job to be created

    Parameters

    • unique: Required<IJobParameters<DATA>>["unique"]
    • Optional opts: IJobParameters["uniqueOpts"]

    Returns this

Generated using TypeDoc