final POC

This commit is contained in:
magdo
2025-11-24 23:28:57 +01:00
parent ce02f55a99
commit 6b3446e9b6
49 changed files with 4634 additions and 4620 deletions
+21
View File
@@ -188,6 +188,17 @@ AppDataSource.initialize()
container.setSocketIO(webSocketService['io']);
gameWebSocketService = container.gameWebSocketService;
logStartup('Game WebSocket service initialized for /game namespace');
// Restore active games from snapshots (if any exist)
gameWebSocketService.restoreAllActiveGames()
.then(restoredCount => {
if (restoredCount > 0) {
logStartup(`Restored ${restoredCount} active game(s) from snapshots`);
}
})
.catch(error => {
logError('Failed to restore games from snapshots', error);
});
})
.catch((error) => {
const dbOptions = AppDataSource.options as any;
@@ -225,6 +236,16 @@ const server = httpServer.listen(PORT, () => {
const gracefulShutdown = async (signal: string) => {
logStartup(`Received ${signal}. Shutting down gracefully...`);
// Snapshot all active games before shutdown
if (gameWebSocketService) {
try {
const snapshotCount = await gameWebSocketService.snapshotAllActiveGames();
logStartup(`Created ${snapshotCount} game snapshot(s) before shutdown`);
} catch (error) {
logError('Failed to snapshot games before shutdown', error as Error);
}
}
server.close(() => {
logStartup('HTTP server closed');