mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
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.
This commit is contained in:
parent
c617e49a63
commit
93f1b97e88
@ -275,8 +275,6 @@ router.post(
|
||||
|
||||
// update the lastMonitoredAt field of the monitors
|
||||
|
||||
const updatePromises: Array<Promise<void>> = [];
|
||||
|
||||
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<Monitor> = [];
|
||||
const monitorWithSecretsPopulatePromises: Array<Promise<Monitor>> = [];
|
||||
const monitorsWithSecretPopulated: Array<Monitor> = [];
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user