Optionalcb: (error?: Error) => voidOptional callback after Agenda is ready
ReadonlyattrsReadonlydefinitionsOptional ReadonlyforkedOptional ReadonlyforkReadonlyreadyCancels any jobs matching the passed options, and removes them from the database.
Options for which jobs to cancel
Set the default concurrency for each job
number of max concurrency
Set the default lock time (in ms) Default is 10 * 60 * 1000 ms (10 minutes)
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!
Optionaloptions: Partial<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!
Optionaloptions: Partial<Disables any jobs matching the passed options, preventing them from being run.
Options for which jobs to disable
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.
OptionalcloseConnection: booleanWhether to close the database connection. Defaults to backend.ownsConnection (true if backend created the connection, false if connection was passed in by user).
Enables any jobs matching the passed options, allowing them to be run.
Options for which jobs to enable
Number of jobs enabled
Creates a scheduled job with given interval and name/names of the job to run
Optionaldata: undefinedOptionaloptions: {Creates a scheduled job with given interval and name/names of the job to run
Optionaldata: undefinedOptionaloptions: {Creates a scheduled job with given interval and name/names of the job to run
Optionaloptions: {Creates a scheduled job with given interval and name/names of the job to run
Optionaloptions: {Get overview statistics for jobs grouped by name. Returns counts of jobs in each state for each job name.
Array of job overviews with state counts
Check if a notification channel is configured
Set the default amount jobs that are allowed to be locked at one time (GLOBAL)
Set a notification channel for real-time job notifications
The notification channel implementation
Create a debounced job that combines rapid submissions into a single execution. Requires a unique key to identify which jobs should be debounced together.
Job name
Job data
Unique constraint to identify jobs (e.g., { 'data.userId': 123 })
Debounce delay in milliseconds
Optionaloptions: { maxWait?: number; strategy?: "trailing" | "leading" }Optional debounce options (maxWait, strategy)
// 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
The callback function
Set the time how often the job processor checks for new jobs to process
Removes all jobs from queue @note: Only use after defining your jobs
Query jobs with database-agnostic options. Returns jobs with computed states and supports filtering by state.
Optionaloptions: JobsQueryOptionsQuery options (name, state, search, pagination)
Jobs with computed states and total count
Starts processing jobs using processJobs() methods, storing an interval ID This method will only resolve if a db has been set up beforehand.
Clear the interval that processes the jobs and unlocks all currently locked jobs
OptionalcloseConnection: booleanWhether to close the database connection. Defaults to backend.ownsConnection (true if backend created the connection, false if connection was passed in by user).
Agenda configuration with backend