Skip to content

Commit

Permalink
spawn a new worker if one of the child workers dies
Browse files Browse the repository at this point in the history
  • Loading branch information
habdelra committed Jan 14, 2025
1 parent 07abcbf commit 80c033f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/realm-server/worker-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ let {
.parseSync();

let isReady = false;
let isExiting = false;
process.on('SIGINT', () => (isExiting = true));
process.on('SIGTERM', () => (isExiting = true));

if (port != null) {
// in tests we start a simple TCP server to communicate to the realm when
// the worker is ready to start processing jobs
Expand Down Expand Up @@ -159,6 +163,13 @@ async function startWorker(urlMappings: URL[][]) {
},
);

worker.on('exit', () => {
if (!isExiting) {
log.info(`worker ${worker.pid} exited. spawning replacement worker`);
startWorker(urlMappings);
}
});

if (worker.stdout) {
worker.stdout.on('data', (data: Buffer) =>
log.info(`[worker ${worker.pid}]: ${data.toString()}`),
Expand Down

0 comments on commit 80c033f

Please sign in to comment.