first commit

This commit is contained in:
yeongaori
2025-08-07 01:18:49 +09:00
commit 13bf4ca7a4
23 changed files with 2614 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
const logger = require('../../modules/colorfulLogger');
const { handleFatalError } = require('../../utils/errorHandler');
const { saveData } = require('../data/dataManager');
function setupProcessHandlers(client) {
async function gracefulShutdown(signal) {
logger.info(`${signal} signal received. Shutting down gracefully...`);
try {
await client.destroy();
await saveData('history');
process.exit(0);
} catch (e) {
logger.error(`Error during ${signal} shutdown: ${e.message}`);
process.exit(1);
}
}
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('uncaughtException', (error) => {
handleFatalError(error, 'Uncaught Exception', client, () => saveData('history'));
});
process.on('unhandledRejection', (reason) => {
const error = reason instanceof Error ? reason : new Error(String(reason));
handleFatalError(error, 'Unhandled Rejection', client, () => saveData('history'));
});
}
module.exports = { setupProcessHandlers };