mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Remove commented out code and unused imports in Monitor.ts
This commit is contained in:
parent
b5fa564cb3
commit
0ecf3fa1e0
@ -10,9 +10,9 @@ import BadDataException from "Common/Types/Exception/BadDataException";
|
|||||||
import { JSONObject } from "Common/Types/JSON";
|
import { JSONObject } from "Common/Types/JSON";
|
||||||
import ObjectID from "Common/Types/ObjectID";
|
import ObjectID from "Common/Types/ObjectID";
|
||||||
import PositiveNumber from "Common/Types/PositiveNumber";
|
import PositiveNumber from "Common/Types/PositiveNumber";
|
||||||
import Semaphore, {
|
// import Semaphore, {
|
||||||
SemaphoreMutex,
|
// SemaphoreMutex,
|
||||||
} from "CommonServer/Infrastructure/Semaphore";
|
// } from "CommonServer/Infrastructure/Semaphore";
|
||||||
import ClusterKeyAuthorization from "CommonServer/Middleware/ClusterKeyAuthorization";
|
import ClusterKeyAuthorization from "CommonServer/Middleware/ClusterKeyAuthorization";
|
||||||
import MonitorProbeService from "CommonServer/Services/MonitorProbeService";
|
import MonitorProbeService from "CommonServer/Services/MonitorProbeService";
|
||||||
import Query from "CommonServer/Types/Database/Query";
|
import Query from "CommonServer/Types/Database/Query";
|
||||||
@ -198,16 +198,24 @@ router.post(
|
|||||||
res: ExpressResponse,
|
res: ExpressResponse,
|
||||||
next: NextFunction,
|
next: NextFunction,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
let mutex: SemaphoreMutex | null = null;
|
// let mutex: SemaphoreMutex | null = null;
|
||||||
|
|
||||||
|
logger.debug("Monitor list API called");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data: JSONObject = req.body;
|
const data: JSONObject = req.body;
|
||||||
const limit: number = (data["limit"] as number) || 100;
|
const limit: number = (data["limit"] as number) || 100;
|
||||||
|
|
||||||
|
logger.debug("Monitor list API called with limit: " + limit);
|
||||||
|
logger.debug("Data:");
|
||||||
|
logger.debug(data);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(req as ProbeExpressRequest).probe ||
|
!(req as ProbeExpressRequest).probe ||
|
||||||
!(req as ProbeExpressRequest).probe?.id
|
!(req as ProbeExpressRequest).probe?.id
|
||||||
) {
|
) {
|
||||||
|
logger.error("Probe not found");
|
||||||
|
|
||||||
return Response.sendErrorResponse(
|
return Response.sendErrorResponse(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
@ -218,6 +226,8 @@ router.post(
|
|||||||
const probeId: ObjectID = (req as ProbeExpressRequest).probe!.id!;
|
const probeId: ObjectID = (req as ProbeExpressRequest).probe!.id!;
|
||||||
|
|
||||||
if (!probeId) {
|
if (!probeId) {
|
||||||
|
logger.error("Probe not found");
|
||||||
|
|
||||||
return Response.sendErrorResponse(
|
return Response.sendErrorResponse(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
@ -225,15 +235,18 @@ router.post(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
mutex = await Semaphore.lock({
|
// mutex = await Semaphore.lock({
|
||||||
key: probeId.toString(),
|
// key: probeId.toString(),
|
||||||
});
|
// });
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
logger.error(err);
|
// logger.error(err);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//get list of monitors to be monitored
|
//get list of monitors to be monitored
|
||||||
|
|
||||||
|
logger.debug("Fetching monitor list");
|
||||||
|
|
||||||
const monitorProbes: Array<MonitorProbe> =
|
const monitorProbes: Array<MonitorProbe> =
|
||||||
await MonitorProbeService.findBy({
|
await MonitorProbeService.findBy({
|
||||||
query: getMonitorFetchQuery((req as OneUptimeRequest).probe!.id!),
|
query: getMonitorFetchQuery((req as OneUptimeRequest).probe!.id!),
|
||||||
@ -257,6 +270,9 @@ router.post(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.debug("Fetched monitor list");
|
||||||
|
logger.debug(monitorProbes);
|
||||||
|
|
||||||
// update the lastMonitoredAt field of the monitors
|
// update the lastMonitoredAt field of the monitors
|
||||||
|
|
||||||
for (const monitorProbe of monitorProbes) {
|
for (const monitorProbe of monitorProbes) {
|
||||||
@ -289,13 +305,13 @@ router.post(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mutex) {
|
// if (mutex) {
|
||||||
try {
|
// try {
|
||||||
await Semaphore.release(mutex);
|
// await Semaphore.release(mutex);
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
logger.error(err);
|
// logger.error(err);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const monitors: Array<Monitor> = monitorProbes
|
const monitors: Array<Monitor> = monitorProbes
|
||||||
.map((monitorProbe: MonitorProbe) => {
|
.map((monitorProbe: MonitorProbe) => {
|
||||||
@ -305,6 +321,9 @@ router.post(
|
|||||||
return Boolean(monitor._id);
|
return Boolean(monitor._id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.debug("Populating secrets");
|
||||||
|
logger.debug(monitors);
|
||||||
|
|
||||||
// check if the monitor needs secrets to be filled.
|
// check if the monitor needs secrets to be filled.
|
||||||
|
|
||||||
const monitorsWithSecretPopulated: Array<Monitor> = [];
|
const monitorsWithSecretPopulated: Array<Monitor> = [];
|
||||||
@ -316,6 +335,9 @@ router.post(
|
|||||||
monitorsWithSecretPopulated.push(monitorWithSecrets);
|
monitorsWithSecretPopulated.push(monitorWithSecrets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("Populated secrets");
|
||||||
|
logger.debug(monitorsWithSecretPopulated);
|
||||||
|
|
||||||
// return the list of monitors to be monitored
|
// return the list of monitors to be monitored
|
||||||
|
|
||||||
return Response.sendEntityArrayResponse(
|
return Response.sendEntityArrayResponse(
|
||||||
@ -326,13 +348,13 @@ router.post(
|
|||||||
Monitor,
|
Monitor,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
try {
|
// try {
|
||||||
if (mutex) {
|
// if (mutex) {
|
||||||
await Semaphore.release(mutex);
|
// await Semaphore.release(mutex);
|
||||||
}
|
// }
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
logger.error(err);
|
// logger.error(err);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user