| 73 | * @private |
| 74 | */ |
| 75 | export 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. |