MerkleTreeLabs / Max-Planck

Social Bot connected to QRL and ZND Blockchains
GNU Affero General Public License v3.0
1 stars 0 forks source link

Close Database connection on SIGTERM|SIGINIT and send `sequelize.close()` #33

Open fr1t2 opened 1 month ago

fr1t2 commented 1 month ago

Example from GPT conversation:


const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
  host: 'localhost',
  dialect: 'mysql',
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  }
});

// Handle the Ctrl+C signal
process.on('SIGINT', async () => {
  console.log('Gracefully shutting down...');
  try {
    await sequelize.close();
    console.log('Database connection closed');
    process.exit(0); // Exit the process after closing the connection
  } catch (err) {
    console.error('Error while closing the database connection:', err);
    process.exit(1);
  }
});

// Your bot logic here

// Example: Simulate bot running
setInterval(() => {
  console.log('Bot is running...');
}, 5000);