MCPcopy
hub / github.com/node-cron/node-cron / schedule

Function schedule

src/node-cron.ts:52–64  ·  view source on GitHub ↗
(expression:string, func: TaskFn | string, options?: TaskOptions)

Source from the content-addressed store, hash-verified

50 * const dailyTask = schedule('0 0 * * *', './tasks/daily-backup.js', { timezone: 'America/New_York' });
51 */
52export 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.

Callers

nothing calls this directly

Calls 4

catchMethod · 0.80
errorMethod · 0.80
createTaskFunction · 0.70
startMethod · 0.65

Tested by

no test coverage detected