mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 23:00:35 +00:00
configure nginx to run in container
This commit is contained in:
+26
-12
@@ -11,6 +11,7 @@ import rateLimit from "express-rate-limit";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const config = getServerConfig();
|
||||
const readyWorkers = new Set();
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
@@ -54,6 +55,31 @@ export async function startMaster() {
|
||||
console.log(`Started worker ${i} (PID: ${worker.process.pid})`);
|
||||
}
|
||||
|
||||
cluster.on("message", (worker, message) => {
|
||||
if (message.type === "WORKER_READY") {
|
||||
const workerId = message.workerId;
|
||||
readyWorkers.add(workerId);
|
||||
console.log(
|
||||
`Worker ${workerId} is ready. (${readyWorkers.size}/${config.numWorkers()} ready)`,
|
||||
);
|
||||
|
||||
// Start scheduling when all workers are ready
|
||||
if (readyWorkers.size === config.numWorkers()) {
|
||||
console.log("All workers ready, starting game scheduling");
|
||||
// let the workers start up
|
||||
const scheduleLobbies = () => {
|
||||
schedulePublicGame().catch((error) => {
|
||||
console.error("Error scheduling public game:", error);
|
||||
});
|
||||
};
|
||||
|
||||
scheduleLobbies();
|
||||
setInterval(scheduleLobbies, config.gameCreationRate());
|
||||
setInterval(() => fetchLobbies(), 250);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle worker crashes
|
||||
cluster.on("exit", (worker, code, signal) => {
|
||||
const workerId = (worker as any).process?.env?.WORKER_ID;
|
||||
@@ -81,18 +107,6 @@ export async function startMaster() {
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Master HTTP server listening on port ${PORT}`);
|
||||
});
|
||||
sleep(5000).then(() => {
|
||||
// let the workers start up
|
||||
const scheduleLobbies = () => {
|
||||
schedulePublicGame().catch((error) => {
|
||||
console.error("Error scheduling public game:", error);
|
||||
});
|
||||
};
|
||||
|
||||
scheduleLobbies();
|
||||
setInterval(scheduleLobbies, config.gameCreationRate());
|
||||
setInterval(() => fetchLobbies(), 250);
|
||||
});
|
||||
}
|
||||
|
||||
// Add lobbies endpoint to list public games for this worker
|
||||
|
||||
@@ -308,6 +308,14 @@ export function startWorker() {
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Worker ${workerId} running on http://localhost:${PORT}`);
|
||||
console.log(`Handling requests with path prefix /w${workerId}/`);
|
||||
// Signal to the master process that this worker is ready
|
||||
if (process.send) {
|
||||
process.send({
|
||||
type: "WORKER_READY",
|
||||
workerId: workerId,
|
||||
});
|
||||
console.log(`Worker ${workerId} signaled ready state to master`);
|
||||
}
|
||||
});
|
||||
|
||||
// Global error handler
|
||||
|
||||
Reference in New Issue
Block a user