ScheduledTask
Use this class to define a scheduled task that will be executed at a given cron schedule.
Example
constructor
(config: ScheduledTaskConfig<C>) => ScheduledTaskid
options
execute
(injector: Injector) => configure
(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
The arguments passed to the execute method of a scheduled task.
injector
InjectorThe injector instance.
scheduledContext
RequestContextA RequestContext instance that is configured for the scheduled task.
params
CThe parameters for the scheduled task.
The configuration for a scheduled task.
id
stringThe unique identifier for the scheduled task.
description
stringThe description for the scheduled task.
params
COptional parameters that will be passed to the execute function.
schedule
string | ((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
timeout
number | string60_000msThe 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
booleantrueWhether the scheduled task should be prevented from running if it is already running.
execute
(args: ScheduledTaskExecutionArgs<C>) => Promise<any>The function that will be executed when the scheduled task is run.