From 41e9a6e0cf0e6f021755770c2fa08d85d69d4ad9 Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Sat, 24 May 2025 22:14:06 +0200 Subject: [PATCH] Fix failed backup bug due to not awaiting log insert #393 --- backend/classes/backup.js | 12 ++++++------ backend/tasks/BackupTask.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/classes/backup.js b/backend/classes/backup.js index 5282ca0..d2c21f0 100644 --- a/backend/classes/backup.js +++ b/backend/classes/backup.js @@ -34,7 +34,7 @@ async function backup(refLog) { if (config.error) { refLog.logData.push({ color: "red", Message: "Backup Failed: Failed to get config" }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); return; } @@ -61,7 +61,7 @@ async function backup(refLog) { console.error("No write permissions for the folder:", backuppath); refLog.logData.push({ color: "red", Message: "Backup Failed: No write permissions for the folder: " + backuppath }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); await pool.end(); return; } @@ -73,7 +73,7 @@ async function backup(refLog) { if (filteredTables.length === 0) { refLog.logData.push({ color: "red", Message: "Backup Failed: No tables to backup" }); refLog.logData.push({ color: "red", Message: "Backup Failed with errors" }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); await pool.end(); return; } @@ -82,9 +82,9 @@ async function backup(refLog) { const directoryPath = path.join(__dirname, "..", backupfolder, `backup_${now.format("yyyy-MM-DD HH-mm-ss")}.json`); refLog.logData.push({ color: "yellow", Message: "Begin Backup " + directoryPath }); const stream = fs.createWriteStream(directoryPath, { flags: "a" }); - stream.on("error", (error) => { + stream.on("error", async (error) => { refLog.logData.push({ color: "red", Message: "Backup Failed: " + error }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); return; }); const backup_data = []; @@ -152,7 +152,7 @@ async function backup(refLog) { } catch (error) { console.log(error); refLog.logData.push({ color: "red", Message: "Backup Failed: " + error }); - Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); + await Logging.updateLog(refLog.uuid, refLog.logData, taskstate.FAILED); } await pool.end(); diff --git a/backend/tasks/BackupTask.js b/backend/tasks/BackupTask.js index 7f55e97..50d780d 100644 --- a/backend/tasks/BackupTask.js +++ b/backend/tasks/BackupTask.js @@ -27,10 +27,10 @@ async function runBackupTask(triggerType = triggertype.Automatic) { console.log("Running Scheduled Backup"); - Logging.insertLog(uuid, triggerType, taskName.backup); + await Logging.insertLog(uuid, triggerType, taskName.backup); await backup(refLog); - Logging.updateLog(uuid, refLog.logData, taskstate.SUCCESS); + await Logging.updateLog(uuid, refLog.logData, taskstate.SUCCESS); sendUpdate("BackupTask", { type: "Success", message: `${triggerType} Backup Completed` }); console.log("Scheduled Backup Complete"); parentPort.postMessage({ status: "complete" });