MCPcopy Index your code
hub / github.com/node-cron/node-cron / createTask

Function createTask

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

Source from the content-addressed store, hash-verified

73 * @private
74 */
75export function createTask(expression: string, func: TaskFn | string, options?: TaskOptions): ScheduledTask {
76 if (options?.distributed && !options.name) {
77 throw new Error('`distributed` requires a `name` (it forms the coordination key shared across instances).');
78 }
79 // The coordinator (per-task / global / env-var default) is resolved when the
80 // task is constructed below; an unset/invalid env-var default throws there,
81 // failing fast at schedule time rather than at the first fire.
82
83 let task: ScheduledTask;
84 if(func instanceof Function){
85 task = new InlineScheduledTask(expression, func, options);
86 } else {
87 const taskPath = solvePath(func);
88 task = new BackgroundScheduledTask(expression, taskPath, options);
89 }
90
91 registry.add(task);
92 return task;
93}
94
95/**
96 * Resolves a relative file path to a file URL path based on the caller's location.

Callers 1

scheduleFunction · 0.70

Calls 2

solvePathFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected