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

Class IpcRunCoordinator

src/coordinator/ipc-run-coordinator.ts:23–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 * by each instance's parent; this only bridges child to its own parent.
22 */
23export class IpcRunCoordinator implements RunCoordinator {
24 private pending = new Map<string, (result: CoordinatorResult) => void>();
25
26 constructor(private channel: IpcChannel) {
27 this.channel.on('message', (message: any) => {
28 if (message?.type !== 'coordinator:result') return;
29 const resolve = this.pending.get(message.reqId);
30 if (resolve) {
31 this.pending.delete(message.reqId);
32 resolve(message);
33 }
34 });
35 }
36
37 shouldRun(key: string, ttlMs: number): Promise<boolean> {
38 const reqId = createID();
39 return new Promise<boolean>((resolve, reject) => {
40 this.pending.set(reqId, (result) => {
41 // The parent reports a coordinator error by replying with `error`; reject
42 // so the runner fails closed (skips the run), mirroring the inline path.
43 if (result.error) reject(new Error(result.error));
44 else resolve(result.allowed);
45 });
46 this.channel.send?.({ type: 'coordinator:shouldRun', key, ttlMs, reqId });
47 });
48 }
49
50 onComplete(key: string): Promise<void> {
51 this.channel.send?.({ type: 'coordinator:complete', key });
52 return Promise.resolve();
53 }
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected