Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
58
Frontend-Learner/node_modules/nitropack/dist/presets/node/runtime/node-cluster.mjs
generated
vendored
Normal file
58
Frontend-Learner/node_modules/nitropack/dist/presets/node/runtime/node-cluster.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import cluster from "node:cluster";
|
||||
import os from "node:os";
|
||||
import {
|
||||
getGracefulShutdownConfig,
|
||||
trapUnhandledNodeErrors
|
||||
} from "nitropack/runtime/internal";
|
||||
function runMaster() {
|
||||
const numberOfWorkers = Number.parseInt(process.env.NITRO_CLUSTER_WORKERS || "") || (os.cpus().length > 0 ? os.cpus().length : 1);
|
||||
for (let i = 0; i < numberOfWorkers; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
let isShuttingDown = false;
|
||||
cluster.on("exit", () => {
|
||||
if (!isShuttingDown) {
|
||||
cluster.fork();
|
||||
}
|
||||
});
|
||||
const shutdownConfig = getGracefulShutdownConfig();
|
||||
if (!shutdownConfig.disabled) {
|
||||
async function onShutdown() {
|
||||
if (isShuttingDown) {
|
||||
return;
|
||||
}
|
||||
isShuttingDown = true;
|
||||
await new Promise((resolve) => {
|
||||
const timeout = setTimeout(() => {
|
||||
console.warn("Timeout reached for graceful shutdown. Forcing exit.");
|
||||
resolve();
|
||||
}, shutdownConfig.timeout);
|
||||
cluster.on("exit", () => {
|
||||
if (Object.values(cluster.workers || {}).every((w) => !w || w.isDead())) {
|
||||
clearTimeout(timeout);
|
||||
resolve();
|
||||
} else {
|
||||
}
|
||||
});
|
||||
});
|
||||
if (shutdownConfig.forceExit) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
for (const signal of shutdownConfig.signals) {
|
||||
process.once(signal, onShutdown);
|
||||
}
|
||||
}
|
||||
}
|
||||
function runWorker() {
|
||||
import("./node-server.mjs").catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
trapUnhandledNodeErrors();
|
||||
if (cluster.isPrimary) {
|
||||
runMaster();
|
||||
} else {
|
||||
runWorker();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue