Skip to content

Commit

Permalink
Add timeouts to complete operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeiown committed Oct 5, 2024
1 parent be04a88 commit 9ecc04f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const { checkIntegrity } = require('./modules/maintenance/integrityChecker');
} catch (err) {
console.error(`Error during initialization:`, err);
} finally {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
await delay(2000);

const { handleExceptionAndRestart, logSystemEvents } = require('./modules/systemEventAndErrorHandler');
const { createTrayIcon } = require('./modules/trayMenu/trayIconManager');
const { fetchDataAndSaveToFile } = require('./modules/alertManager/apiRequestHandler');
Expand Down
9 changes: 0 additions & 9 deletions modules/maintenance/integrityChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const path = require('path');
const { backupConfigFiles } = require('./configFilesBackupHandler');
const { logEvent } = require('../logger');

const lockFilePath = path.join(process.env.TEMP, 'alertserver_recovery.tmp');

const checkIntegrity = async () => {
const filesToCheck = ['alert_types.json', 'location.json', 'messages.json', 'package.json'];
const recoveryBatPath = path.join(process.cwd(), 'start_recovery.bat');
Expand All @@ -32,13 +30,6 @@ const checkIntegrity = async () => {
return;
}

if (fs.existsSync(lockFilePath)) {
return;
}

const timestamp = Date.now().toString();
fs.writeFileSync(lockFilePath, timestamp, 'utf-8');

backupConfigFiles();

const logMessage = `Performing a restore from a repository`;
Expand Down
12 changes: 7 additions & 5 deletions modules/maintenance/updateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ const downloadAndInstallUpdate = (latestVersion) => {
fs.unlinkSync(zipPath);
logEvent(messages.msg_81);

exec(`start "" "${setupPath}"`, (err) => {
if (err) {
logEvent(`${messages.msg_82} ${err.message}`);
}
});
setTimeout(() => {
exec(`start "" "${setupPath}"`, (err) => {
if (err) {
logEvent(`${messages.msg_82} ${err.message}`);
}
});
}, 2000);
})
.on('error', (err) => {
logEvent(`${messages.msg_83} ${err.message}`);
Expand Down
10 changes: 2 additions & 8 deletions start_recovery.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
title Alert Server Recovery

:: --- Initial Recovery Preparation ---
cls & echo Starting the recovery process...
echo. & echo Check the event.log file for details.
cls & echo Important files are corrupted.
echo. & echo Starting the recovery process...
echo. & timeout /t 3 /nobreak > nul

taskkill /f /im node.exe >nul 2>nul
Expand Down Expand Up @@ -65,12 +65,6 @@ if exist "%destFile%" (
copy "%sourceFile%" "%destFile%"

:: --- Finalizing the Recovery Process and Restart Alert Server ---
set tempFilePath=%TEMP%\alertserver_recovery.tmp

if exist "%tempFilePath%" (
del "%tempFilePath%"
)

echo. & echo Recovery is complete.
timeout /t 2 /nobreak > nul
echo. & echo Note: If the configuration files are restored after corruption the settings will be restored to their default values.
Expand Down

0 comments on commit 9ecc04f

Please sign in to comment.