Skip to main content

ScheduledTask

Use this class to define a scheduled task that will be executed at a given cron schedule.

Example

Ts
Signature

constructor

method(config: ScheduledTaskConfig<C>) => ScheduledTask

id

property

options

property

execute

method(injector: Injector) =>

configure

method(additionalConfig: Partial<Pick<ScheduledTaskConfig<C>, 'schedule' | 'timeout' | 'params'>>) =>

This method allows you to further configure existing scheduled tasks. For example, you may wish to change the schedule or timeout of a task, without having to define a new task.

Example

Ts

The arguments passed to the execute method of a scheduled task.

Signature

injector

propertyInjector

The injector instance.

scheduledContext

A RequestContext instance that is configured for the scheduled task.

params

propertyC

The parameters for the scheduled task.

The configuration for a scheduled task.

Signature

id

propertystring

The unique identifier for the scheduled task.

description

propertystring

The description for the scheduled task.

params

propertyC

Optional parameters that will be passed to the execute function.

schedule

propertystring | ((cronTime: typeof CronTime) => string)

The cron schedule for the scheduled task. This can be a standard cron expression or a function that returns a cron-time-generator expression.

Example

Ts

timeout

propertynumber | string
Default:60_000ms

The timeout for the scheduled task. If the task takes longer than the timeout, the task will be considered to have failed with a timeout error.

preventOverlap

propertyboolean
Default:true

Whether the scheduled task should be prevented from running if it is already running.

execute

method(args: ScheduledTaskExecutionArgs<C>) => Promise<any>

The function that will be executed when the scheduled task is run.

Was this chapter helpful?
Report Issue
Edited Feb 10, 2026ยทEdit this page