Agenda - v6.0.0
    Preparing search index...

    Class Agenda

    Hierarchy

    • EventEmitter
      • Agenda
    Index

    Constructors

    • Parameters

      • config: AgendaOptions

        Agenda configuration with backend

      • Optionalcb: (error?: Error) => void

        Optional callback after Agenda is ready

      Returns Agenda

    Properties

    definitions: { [name: string]: JobDefinition<unknown> } = {}
    forkedWorker?: boolean
    forkHelper?: { options?: ForkOptions; path: string }
    ready: Promise<void>

    Methods

    • Cancels any jobs matching the passed options, and removes them from the database.

      Parameters

      Returns Promise<number>

    • Given a name and some data, create a new job

      Parameters

      • name: string

      Returns Job<void>

    • Given a name and some data, create a new job

      Type Parameters

      • DATA = unknown

      Parameters

      • name: string
      • data: DATA

      Returns Job<DATA>

    • Set the default concurrency for each job

      Parameters

      • num: number

        number of max concurrency

      Returns Agenda

    • Set the default lock time (in ms) Default is 10 * 60 * 1000 ms (10 minutes)

      Parameters

      • ms: number

      Returns Agenda

    • Set default lock limit per job type

      Parameters

      • num: number

      Returns Agenda

    • Setup definition for job Method is used by consumers of lib to setup their functions BREAKING CHANGE in v4: options moved from 2nd to 3rd parameter!

      Type Parameters

      • DATA = any

      Parameters

      • name: string
      • processor: (agendaJob: Job<DATA>, done: (error?: Error) => void) => void
      • Optionaloptions: Partial<
            Pick<
                JobDefinition<unknown>,
                "lockLimit" | "lockLifetime" | "concurrency" | "backoff",
            >,
        > & { priority?: JobPriority }

      Returns void

    • Setup definition for job Method is used by consumers of lib to setup their functions BREAKING CHANGE in v4: options moved from 2nd to 3rd parameter!

      Type Parameters

      • DATA = any

      Parameters

      • name: string
      • processor: (agendaJob: Job<DATA>) => Promise<void>
      • Optionaloptions: Partial<
            Pick<
                JobDefinition<unknown>,
                "lockLimit" | "lockLifetime" | "concurrency" | "backoff",
            >,
        > & { priority?: JobPriority }

      Returns void

    • Disables any jobs matching the passed options, preventing them from being run.

      Parameters

      Returns Promise<number>

      Number of jobs disabled

    • Waits for all currently running jobs to finish before stopping. This allows for a graceful shutdown where jobs complete their work. Unlike stop(), this method waits for running jobs to complete instead of unlocking them.

      Parameters

      • OptionalcloseConnection: boolean

        Whether to close the database connection. Defaults to backend.ownsConnection (true if backend created the connection, false if connection was passed in by user).

      Returns Promise<void>

    • Enables any jobs matching the passed options, allowing them to be run.

      Parameters

      Returns Promise<number>

      Number of jobs enabled

    • Creates a scheduled job with given interval and name/names of the job to run

      Parameters

      • interval: string | number
      • names: string[]
      • Optionaldata: undefined
      • Optionaloptions: {
            endDate?: string | Date;
            forkMode?: boolean;
            skipDays?: number[];
            skipImmediate?: boolean;
            startDate?: string | Date;
            timezone?: string;
        }

      Returns Promise<Job<void>[]>

    • Creates a scheduled job with given interval and name/names of the job to run

      Parameters

      • interval: string | number
      • name: string
      • Optionaldata: undefined
      • Optionaloptions: {
            endDate?: string | Date;
            forkMode?: boolean;
            skipDays?: number[];
            skipImmediate?: boolean;
            startDate?: string | Date;
            timezone?: string;
        }

      Returns Promise<Job<void>>

    • Creates a scheduled job with given interval and name/names of the job to run

      Type Parameters

      • DATA = unknown

      Parameters

      • interval: string | number
      • names: string[]
      • data: DATA
      • Optionaloptions: {
            endDate?: string | Date;
            forkMode?: boolean;
            skipDays?: number[];
            skipImmediate?: boolean;
            startDate?: string | Date;
            timezone?: string;
        }

      Returns Promise<Job<DATA>[]>

    • Creates a scheduled job with given interval and name/names of the job to run

      Type Parameters

      • DATA = unknown

      Parameters

      • interval: string | number
      • name: string
      • data: DATA
      • Optionaloptions: {
            endDate?: string | Date;
            forkMode?: boolean;
            skipDays?: number[];
            skipImmediate?: boolean;
            startDate?: string | Date;
            timezone?: string;
        }

      Returns Promise<Job<DATA>>

    • Get overview statistics for jobs grouped by name. Returns counts of jobs in each state for each job name.

      Returns Promise<JobsOverview[]>

      Array of job overviews with state counts

    • Check if a notification channel is configured

      Returns boolean

    • Returns boolean

    • Set the default amount jobs that are allowed to be locked at one time (GLOBAL)

      Parameters

      • num: number

      Returns Agenda

    • Set the concurrency for jobs (globally), type does not matter

      Parameters

      • num: number

      Returns Agenda

    • Create a job for this exact moment

      Type Parameters

      • DATA = void

      Parameters

      • name: string

      Returns Promise<Job<DATA>>

    • Create a job for this exact moment

      Type Parameters

      • DATA = unknown

      Parameters

      • name: string
      • data: DATA

      Returns Promise<Job<DATA>>

    • Create a debounced job that combines rapid submissions into a single execution. Requires a unique key to identify which jobs should be debounced together.

      Type Parameters

      • DATA = unknown

      Parameters

      • name: string

        Job name

      • data: DATA

        Job data

      • uniqueKey: Record<string, unknown>

        Unique constraint to identify jobs (e.g., { 'data.userId': 123 })

      • debounceMs: number

        Debounce delay in milliseconds

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

        Optional debounce options (maxWait, strategy)

      Returns Promise<Job<DATA>>

      // Debounce search index updates by entity type
      await agenda.nowDebounced(
      'updateSearchIndex',
      { entityType: 'products' },
      { 'data.entityType': 'products' },
      2000
      );

      // With maxWait to guarantee execution within 30s
      await agenda.nowDebounced(
      'syncUser',
      { userId: 123 },
      { 'data.userId': 123 },
      5000,
      { maxWait: 30000 }
      );
    • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.on('foo', () => console.log('a'));
      myEE.prependListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Parameters

      • event: "ready"
      • listener: () => void

        The callback function

      Returns this

      v0.1.101

    • Parameters

      • event: "error"
      • listener: (error: Error) => void

      Returns this

    • Parameters

      • event: "fail"
      • listener: (error: Error, job: JobWithId) => void

      Returns this

    • Parameters

      • event: "success"
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      • event: "start"
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      • event: "complete"
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      Returns this

    • Parameters

      • event: "retry exhausted"
      • listener: (error: Error, job: JobWithId) => void

      Returns this

    • Parameters

      • event: `fail:${string}`
      • listener: (error: Error, job: JobWithId) => void

      Returns this

    • Parameters

      • event: `success:${string}`
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      • event: `start:${string}`
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      • event: `complete:${string}`
      • listener: (job: JobWithId) => void

      Returns this

    • Parameters

      Returns this

    • Parameters

      • event: `retry exhausted:${string}`
      • listener: (error: Error, job: JobWithId) => void

      Returns this

    • Set the time how often the job processor checks for new jobs to process

      Parameters

      • time: string | number

      Returns Agenda

    • Removes all jobs from queue @note: Only use after defining your jobs

      Returns Promise<number>

    • Query jobs with database-agnostic options. Returns jobs with computed states and supports filtering by state.

      Parameters

      • Optionaloptions: JobsQueryOptions

        Query options (name, state, search, pagination)

      Returns Promise<JobsResult<unknown>>

      Jobs with computed states and total count

    • Parameters

      • jobId: string

      Returns Promise<void>

    • Schedule a job or jobs at a specific time

      Type Parameters

      • DATA = void

      Parameters

      • when: string | Date
      • names: string[]
      • Optionaldata: undefined
      • Optionaloptions: { endDate?: string | Date; skipDays?: number[]; startDate?: string | Date }

      Returns Promise<Job<DATA>[]>

    • Schedule a job or jobs at a specific time

      Type Parameters

      • DATA = void

      Parameters

      • when: string | Date
      • names: string
      • Optionaldata: undefined
      • Optionaloptions: { endDate?: string | Date; skipDays?: number[]; startDate?: string | Date }

      Returns Promise<Job<DATA>>

    • Schedule a job or jobs at a specific time

      Type Parameters

      • DATA = unknown

      Parameters

      • when: string | Date
      • names: string[]
      • data: DATA
      • Optionaloptions: { endDate?: string | Date; skipDays?: number[]; startDate?: string | Date }

      Returns Promise<Job<DATA>[]>

    • Schedule a job or jobs at a specific time

      Type Parameters

      • DATA = unknown

      Parameters

      • when: string | Date
      • name: string
      • data: DATA
      • Optionaloptions: { endDate?: string | Date; skipDays?: number[]; startDate?: string | Date }

      Returns Promise<Job<DATA>>

    • Starts processing jobs using processJobs() methods, storing an interval ID This method will only resolve if a db has been set up beforehand.

      Returns Promise<void>

    • Clear the interval that processes the jobs and unlocks all currently locked jobs

      Parameters

      • OptionalcloseConnection: boolean

        Whether to close the database connection. Defaults to backend.ownsConnection (true if backend created the connection, false if connection was passed in by user).

      Returns Promise<void>