(message: any)
| 5 | import { IpcRunCoordinator } from "../../coordinator/ipc-run-coordinator"; |
| 6 | |
| 7 | export async function startDaemon(message: any): Promise<ScheduledTask> { |
| 8 | const script = await importTaskModule(message.path); |
| 9 | |
| 10 | // The inline task in the daemon stays silent; the parent process logs from |
| 11 | // the forwarded events using the user's configured logger. |
| 12 | const options: TaskOptions = { ...(message.options || {}), logger: noopLogger }; |
| 13 | |
| 14 | // The real coordinator lives in the parent; bridge to it over IPC so the |
| 15 | // daemon coordinates through the same shared backend as every instance. |
| 16 | if (options.distributed) { |
| 17 | options.runCoordinator = new IpcRunCoordinator(process); |
| 18 | } |
| 19 | |
| 20 | const task = new InlineScheduledTask(message.cron, script.task, options); |
| 21 | |
| 22 | task.on('task:started', (context => sendEvent('task:started', context))); |
| 23 | |
| 24 | task.on('task:stopped', (context => sendEvent('task:stopped', context))); |
| 25 | |
| 26 | task.on('task:destroyed', (context => sendEvent('task:destroyed', context))); |
| 27 | |
| 28 | task.on('execution:started', (context => sendEvent('execution:started', context))); |
| 29 | |
| 30 | task.on('execution:finished', (context => sendEvent('execution:finished', context))); |
| 31 | |
| 32 | task.on('execution:failed', (context => sendEvent('execution:failed', context))); |
| 33 | |
| 34 | task.on('execution:missed', (context => sendEvent('execution:missed', context))); |
| 35 | |
| 36 | task.on('execution:overlap', (context => sendEvent('execution:overlap', context))); |
| 37 | |
| 38 | task.on('execution:maxReached', (context => sendEvent('execution:maxReached', context))); |
| 39 | |
| 40 | task.on('execution:skipped', (context => sendEvent('execution:skipped', context))); |
| 41 | |
| 42 | if (process.send) process.send({ event: 'daemon:started' }); |
| 43 | |
| 44 | task.start(); |
| 45 | return task; |
| 46 | } |
| 47 | |
| 48 | /* Loading the task file is the one step that legitimately fails at runtime |
| 49 | * (missing file, a runtime that cannot run the file, unsupported TS syntax in |
no test coverage detected