MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / shutdown

Method shutdown

src/app.js:319–363  ·  view source on GitHub ↗
(reason = 'UNKNOWN')

Source from the content-addressed store, hash-verified

317 }
318
319 async shutdown(reason = 'UNKNOWN') {
320 shutdownLog(`Bot is shutting down (${reason})...`);
321 logger.info(`\n${'='.repeat(60)}`);
322 logger.info(`🛑 Graceful Shutdown Initiated (${reason})`);
323 logger.info(`${'='.repeat(60)}`);
324
325 try {
326
327 logger.info('Stopping cron jobs...');
328 cron.getTasks().forEach(task => task.stop());
329 logger.info('✅ Cron jobs stopped');
330
331 // Close database connection
332 // Close database connection
333 if (this.db && this.db.db) {
334 logger.info('Closing database connection...');
335 try {
336 if (this.db.db.pool) {
337 await this.db.db.pool.end();
338 logger.info('✅ Database connection closed');
339 }
340 } catch (error) {
341 logger.warn('Error closing database pool:', error.message);
342 }
343 }
344
345 logger.info('Destroying Discord client...');
346 if (this.isReady()) {
347 try {
348 this.destroy();
349 logger.info('✅ Discord client destroyed');
350 } catch (error) {
351
352 logger.warn('Discord client destroy warning (non-critical):', error.message);
353 }
354 }
355
356 logger.info('✅ Graceful shutdown complete');
357 shutdownLog('Bot stopped successfully.');
358 process.exit(0);
359 } catch (error) {
360 logger.error('Error during graceful shutdown:', error);
361 process.exit(1);
362 }
363 }
364}
365
366try {

Callers 2

setupShutdownFunction · 0.80
app.jsFile · 0.80

Calls 1

shutdownLogFunction · 0.90

Tested by

no test coverage detected