···4545 // Give a moment for the message to be delivered before restarting
4646 setTimeout(async () => {
4747 try {
4848+ // Force save queue before restart to prevent data loss
4949+ const queueManager = require('../../../queue/queueManager');
5050+ await queueManager.saveQueueToDisk();
5151+ console.log('Queue saved before restart');
5252+4853 // Restart the bot using PM2
4954 await execAsync('pm2 restart --update-env stagehand');
5055 } catch (restartError) {
5656+ // SIGINT is expected when PM2 restarts the process, not an actual error
5757+ if (restartError.signal === 'SIGINT' && restartError.stdout && restartError.stdout.includes('[PM2]')) {
5858+ console.log('Bot restart initiated successfully (SIGINT received as expected)');
5959+ return;
6060+ }
5161 console.error('Error restarting bot:', restartError);
5262 this.bot.sendMessage(chatId, `❌ Failed to restart bot: ${restartError.message}\n\nPlease restart the bot manually.`);
5363 }
+16-2
utils/updater.js
···90909191 // Restart the bot using PM2
9292 console.log('Restarting bot with PM2...');
9393- await execAsync('pm2 restart --update-env stagehand');
9494- console.log('Bot restarted successfully');
9393+ try {
9494+ // Force save queue before restart to prevent data loss
9595+ const queueManager = require('../queue/queueManager');
9696+ await queueManager.saveQueueToDisk();
9797+ console.log('Queue saved before restart');
9898+9999+ await execAsync('pm2 restart --update-env stagehand');
100100+ console.log('Bot restarted successfully');
101101+ } catch (restartError) {
102102+ // SIGINT is expected when PM2 restarts the process, not an actual error
103103+ if (restartError.signal === 'SIGINT' && restartError.stdout && restartError.stdout.includes('[PM2]')) {
104104+ console.log('Bot restart initiated successfully (SIGINT received as expected)');
105105+ } else {
106106+ throw restartError;
107107+ }
108108+ }
95109 } else {
96110 console.log('No updates found');
97111 }