(expression:string, func: TaskFn | string, options?: TaskOptions)
| 50 | * const dailyTask = schedule('0 0 * * *', './tasks/daily-backup.js', { timezone: 'America/New_York' }); |
| 51 | */ |
| 52 | export function schedule(expression:string, func: TaskFn | string, options?: TaskOptions): ScheduledTask { |
| 53 | const task = createTask(expression, func, options); |
| 54 | // Background tasks start asynchronously and can fail (e.g. the task file |
| 55 | // cannot be loaded). Route that failure to the logger instead of leaving it |
| 56 | // as an unhandled rejection. |
| 57 | const started = task.start(); |
| 58 | if (started && typeof (started as Promise<void>).catch === 'function') { |
| 59 | (started as Promise<void>).catch((error: any) => { |
| 60 | (options?.logger || logger).error(`Failed to start scheduled task: ${error?.message ?? error}`); |
| 61 | }); |
| 62 | } |
| 63 | return task; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates a task instance based on the provided parameters adding it to the registry. |
nothing calls this directly
no test coverage detected