Promisified bot process

This commit is contained in:
2023-06-26 09:41:31 +02:00
parent a48b62833d
commit c50998eb82

View File

@@ -149,9 +149,8 @@ async function startBot(accountName) {
}
}
try {
// execSync(`timeout 150m bash -c "${commandPrefix} ${commandSuffix}; exit"`, { stdio: 'inherit', shell: '/bin/bash' });
const childProcess = spawn('bash', ['-c', `${commandPrefix} ${commandSuffix}`], { stdio: 'inherit' });
return new Promise((resolve, reject) => {
const childProcess = spawn('timeout 150m bash', ['-c', `${commandPrefix} ${commandSuffix}`], { stdio: 'inherit' });
childProcess.stdout.on('data', (data) => {
console.log(`[${accountName}] ${data.toString()}`);
@@ -162,19 +161,25 @@ async function startBot(accountName) {
}
});
childProcess.on('close', (code) => {
childProcess.on('exit', (code) => {
if (code !== 0) {
consoleLog(`[${host}] Bot process for ${accountName} exited with code ${code}. Restarting...`, 'error');
startBot(accountName);
startBot(accountName).then(resolve).catch(reject);
}
else {
resolve();
}
});
}
catch (error) {
consoleLog(`[${host}] Failed to start bot for ${accountName}.`, 'error');
}
childProcess.on('error', (err) => {
consoleLog(`[${host}] Failed to start bot for ${accountName}.`, 'error');
reject(err);
});
});
}
else {
consoleLog(`[${host}] File ${accountPath} does not exist, skipping starting bot for this VPN!`, 'error');
return Promise.reject(`File ${accountPath} does not exist.`);
}
}