Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick fix #61

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion server/controllers/sessionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,21 @@ const updateRooms = async (sessionToken, chatRooms) => {
}
};

// Drops all sessions
const dropAll = async () => {
try {
await Session.collection.drop();
console.log('Sessions collection dropped successfully');
} catch (error) {
console.error('Error dropping sessions:', error);
}
}

module.exports = {
loadUser,
findExistingSession,
deactivateSession,
createSession,
updateRooms
updateRooms,
dropAll
};
24 changes: 2 additions & 22 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ connectDB()
.then(() => {
// Load rooms
roomController.loadGeoJSONdata();
}).then(() => {
sessionController.dropAll();
})

// managers
Expand Down Expand Up @@ -129,28 +131,6 @@ io.on('connection', async (socket) => {
});
});

async function gracefulShutdown(signal) {
console.log(`\n${signal} signal received. Starting graceful shutdown...`);

// Create array of promises for all deactivation operations
const deactivationPromises = Array.from(io.sockets.sockets.values()).map(socket =>
sessionController.deactivateSession(socket.sessionToken)
);

try {
// Wait for all deactivations to complete
await Promise.all(deactivationPromises);
console.log('All sessions deactivated successfully');
} catch (error) {
console.error('Error during session deactivation:', error);
}

process.exit(0);
}

process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('SIGINT', () => gracefulShutdown('SIGINT'));

const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '0.0.0.0';
server.listen(PORT, HOST, () => {
Expand Down