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

Function bind

src/tasks/background-scheduled-task/daemon.ts:131–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129
130
131export function bind(){
132 let task: ScheduledTask;
133
134 process.on('message', async (message: any) => {
135 switch(message.command){
136 case 'task:start':
137 try {
138 task = await startDaemon(message);
139 } catch (error: any) {
140 // Report the failure to the parent so it can reject start() with the
141 // real cause, instead of crashing the daemon with an opaque exit.
142 if (process.send) process.send({ event: 'daemon:error', jsonError: serializeError(error) });
143 }
144 return task;
145 case 'task:stop':
146 if(task) task.stop();
147 return task;
148 case 'task:destroy':
149 if(task) task.destroy();
150 return task;
151 case 'task:execute':
152 try {
153 if (task) await task.execute();
154 } catch(error: any){
155 logger.debug('Daemon task:execute falied:', error);
156 }
157 return task;
158 }
159 });
160
161 // When the parent dies the IPC channel disconnects. Exit instead of lingering
162 // as an orphan: an orphaned daemon would keep running the schedule on its own,
163 // and a distributed task's IPC coordination would hang with no parent to reply.
164 process.on('disconnect', () => process.exit(0));
165}
166
167bind();

Callers 2

daemon.test.tsFile · 0.90
daemon.tsFile · 0.85

Calls 7

startDaemonFunction · 0.85
serializeErrorFunction · 0.85
debugMethod · 0.80
onMethod · 0.65
stopMethod · 0.65
destroyMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected