Agenda - v6.0.0
    Preparing search index...

    Class Job<DATA>

    Type Parameters

    • DATA = unknown | void
    Index

    Constructors

    • creates a new job object

      Type Parameters

      • DATA = unknown

      Parameters

      • agenda: Agenda
      • args: Partial<JobParameters<void>> & { name: string; type: "normal" | "single" }
      • OptionalbyJobProcessor: boolean

      Returns Job<DATA>

    • Type Parameters

      • DATA = unknown

      Parameters

      • agenda: Agenda
      • args: Partial<JobParameters<DATA>> & {
            data: DATA;
            name: string;
            type: "normal" | "single";
        }
      • OptionalbyJobProcessor: boolean

      Returns Job<DATA>

    Properties

    agenda: Agenda
    gotTimerToExecute: boolean

    internal variable to ensure a job does not set unlimited numbers of setTimeouts if the job is not processed immediately

    Methods

    • Parameters

      • Optionalerror: Error

      Returns void

    • Configure debounce behavior for this job. Debouncing delays job execution and resets the timer on subsequent saves, ensuring the job only runs once after a quiet period.

      IMPORTANT: Requires a unique constraint to be set via .unique(). The unique constraint identifies which jobs should be debounced together.

      Parameters

      • delay: number

        Debounce window in milliseconds

      • Optionaloptions: { maxWait?: number; strategy?: "trailing" | "leading" }

        Optional configuration (maxWait, strategy)

      Returns this

      // Basic trailing debounce - execute 2s after last save
      await agenda.create('updateIndex', { entityId: 123 })
      .unique({ 'data.entityId': 123 })
      .debounce(2000)
      .save();

      // With maxWait - guarantee execution within 30s
      await agenda.create('syncUser', { userId: 456 })
      .unique({ 'data.userId': 456 })
      .debounce(5000, { maxWait: 30000 })
      .save();

      // Leading strategy - execute immediately, ignore subsequent calls
      await agenda.create('notify', { channel: '#alerts' })
      .unique({ 'data.channel': '#alerts' })
      .debounce(60000, { strategy: 'leading' })
      .save();
    • Prevents the job from running

      Returns this

    • Allows job to run

      Returns this

    • Sets the end date for the job. The job will not run after this date (nextRunAt will be set to null).

      Parameters

      • dateInput: string | Date

      Returns this

    • Fails the job with a reason (error) specified

      Parameters

      • reason: string | Error

      Returns this

    • if set, a job is forked via node child process and runs in a seperate/own thread

      Parameters

      • enableForkMode: boolean

      Returns this

    • Returns string | true | Error | undefined

    • Returns Promise<boolean>

    • Returns 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)

    • Sets priority of the job

      Parameters

      • priority: JobPriority

        priority of when job should be queued

      Returns this

    • Remove the job from database

      Returns Promise<number>

    • Sets a job to repeat at a specific time

      Parameters

      • time: string

      Returns this

    • Sets a job to repeat every X amount of time

      Parameters

      • interval: string | number
      • options: { skipImmediate?: boolean; timezone?: string } = {}

      Returns this

    • Returns Promise<void>

    • Returns Promise<void>

    • Saves a job to database

      Returns Promise<Job<unknown>>

    • Schedules a job to run at specified time. Date constraints (startDate, endDate, skipDays) are applied if set.

      Parameters

      • time: string | Date

      Returns this

    • Sets the days of the week to skip. The job will not run on these days.

      Parameters

      • days: number[]

        Array of days to skip (0 = Sunday, 1 = Monday, ..., 6 = Saturday)

      Returns this

    • Sets the start date for the job. The job will not run before this date.

      Parameters

      • dateInput: string | Date

      Returns this

    • Given a job, turn it into an JobParameters object

      Parameters

      • excludeProcessorFields: boolean = false

        If true, excludes fields managed by the job processor

      Returns JobParameters

    • Updates "lockedAt" time so the job does not get picked up again

      Parameters

      • Optionalprogress: number

        0 to 100

      Returns Promise<void>

    • Data to ensure is unique for job to be created

      Parameters

      • unique: Record<string, unknown>
      • Optionalopts: UniqueOpts

      Returns this