Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | // Clustered entrypoint for the Next.js standalone server (prod image only). const cluster = require("cluster"); // eslint-disable-line const WEB_WORKER_COUNT = 4; if (!cluster.isPrimary) { require("./server.js"); // eslint-disable-line } else { let shuttingDown = false; console.log( `[cluster] primary ${process.pid} starting ${WEB_WORKER_COUNT} worker(s)`, ); for (let i = 0; i < WEB_WORKER_COUNT; i++) { cluster.fork(); } cluster.on("exit", (worker, code, signal) => { Iif (shuttingDown) return; shuttingDown = true; console.error( `[cluster] worker ${worker.process.pid} exited (code=${code}, signal=${signal}); stopping all workers`, ); for (const other of Object.values(cluster.workers)) { other.process.kill("SIGTERM"); } process.exitCode = 1; }); const shutdown = (signal) => { Iif (shuttingDown) return; shuttingDown = true; console.log(`[cluster] ${signal} received, stopping workers`); for (const worker of Object.values(cluster.workers)) { worker.process.kill(signal); } }; process.on("SIGTERM", () => shutdown("SIGTERM")); process.on("SIGINT", () => shutdown("SIGINT")); } |