this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: enhance updater and update command to save queue before bot restart and improve error handling

+26 -2
+10
bot/telegrambot/commands/update.js
··· 45 45 // Give a moment for the message to be delivered before restarting 46 46 setTimeout(async () => { 47 47 try { 48 + // Force save queue before restart to prevent data loss 49 + const queueManager = require('../../../queue/queueManager'); 50 + await queueManager.saveQueueToDisk(); 51 + console.log('Queue saved before restart'); 52 + 48 53 // Restart the bot using PM2 49 54 await execAsync('pm2 restart --update-env stagehand'); 50 55 } catch (restartError) { 56 + // SIGINT is expected when PM2 restarts the process, not an actual error 57 + if (restartError.signal === 'SIGINT' && restartError.stdout && restartError.stdout.includes('[PM2]')) { 58 + console.log('Bot restart initiated successfully (SIGINT received as expected)'); 59 + return; 60 + } 51 61 console.error('Error restarting bot:', restartError); 52 62 this.bot.sendMessage(chatId, `❌ Failed to restart bot: ${restartError.message}\n\nPlease restart the bot manually.`); 53 63 }
+16 -2
utils/updater.js
··· 90 90 91 91 // Restart the bot using PM2 92 92 console.log('Restarting bot with PM2...'); 93 - await execAsync('pm2 restart --update-env stagehand'); 94 - console.log('Bot restarted successfully'); 93 + try { 94 + // Force save queue before restart to prevent data loss 95 + const queueManager = require('../queue/queueManager'); 96 + await queueManager.saveQueueToDisk(); 97 + console.log('Queue saved before restart'); 98 + 99 + await execAsync('pm2 restart --update-env stagehand'); 100 + console.log('Bot restarted successfully'); 101 + } catch (restartError) { 102 + // SIGINT is expected when PM2 restarts the process, not an actual error 103 + if (restartError.signal === 'SIGINT' && restartError.stdout && restartError.stdout.includes('[PM2]')) { 104 + console.log('Bot restart initiated successfully (SIGINT received as expected)'); 105 + } else { 106 + throw restartError; 107 + } 108 + } 95 109 } else { 96 110 console.log('No updates found'); 97 111 }