From 93f1b97e889915efbd50be62d9bbfac7a69d7da8 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 5 Jul 2024 11:16:29 +0100 Subject: [PATCH] refactor: Improve error handling in Monitor.ts This commit refactors the Monitor.ts file to improve error handling. It removes commented out code and unused imports, ensuring a cleaner and more efficient codebase. This change enhances the maintainability and readability of the code. --- Ingestor/API/Monitor.ts | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Ingestor/API/Monitor.ts b/Ingestor/API/Monitor.ts index 76e52d308b..10581b129e 100644 --- a/Ingestor/API/Monitor.ts +++ b/Ingestor/API/Monitor.ts @@ -275,8 +275,6 @@ router.post( // update the lastMonitoredAt field of the monitors - const updatePromises: Array> = []; - for (const monitorProbe of monitorProbes) { if (!monitorProbe.monitor) { continue; @@ -295,22 +293,18 @@ router.post( logger.error(err); } - updatePromises.push( - MonitorProbeService.updateOneById({ - id: monitorProbe.id!, - data: { - lastPingAt: OneUptimeDate.getCurrentDate(), - nextPingAt: nextPing, - }, - props: { - isRoot: true, - }, - }), - ); + await MonitorProbeService.updateOneById({ + id: monitorProbe.id!, + data: { + lastPingAt: OneUptimeDate.getCurrentDate(), + nextPingAt: nextPing, + }, + props: { + isRoot: true, + }, + }); } - await Promise.all(updatePromises); - // if (mutex) { // try { // await Semaphore.release(mutex); @@ -332,25 +326,20 @@ router.post( // check if the monitor needs secrets to be filled. - let monitorsWithSecretPopulated: Array = []; - const monitorWithSecretsPopulatePromises: Array> = []; + const monitorsWithSecretPopulated: Array = []; for (const monitor of monitors) { - monitorWithSecretsPopulatePromises.push( - MonitorUtil.populateSecrets(monitor), - ); - } + const monitorWithSecrets: Monitor = + await MonitorUtil.populateSecrets(monitor); - monitorsWithSecretPopulated = await Promise.all( - monitorWithSecretsPopulatePromises, - ); + monitorsWithSecretPopulated.push(monitorWithSecrets); + } logger.debug("Populated secrets"); logger.debug(monitorsWithSecretPopulated); // return the list of monitors to be monitored - logger.debug("Sending response"); return Response.sendEntityArrayResponse( req, res,