fix: Add checkedAt property to IncomingMonitorRequest and update its usage in request processing

This commit is contained in:
Simon Larsen
2025-05-08 13:43:33 +01:00
parent 790bd493bb
commit bc6e921dca
4 changed files with 15 additions and 3 deletions

View File

@@ -91,7 +91,8 @@ export default class IncomingRequestCriteria {
const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes(
lastCheckTime,
OneUptimeDate.getCurrentDate(),
(input.dataToProcess as IncomingMonitorRequest)?.checkedAt ||
OneUptimeDate.getCurrentDate(),
);
logger.debug("Difference in minutes: " + differenceInMinutes);

View File

@@ -11,4 +11,5 @@ export default interface IncomingMonitorRequest {
requestMethod?: HTTPMethod | undefined;
incomingRequestReceivedAt: Date;
onlyCheckForIncomingRequestReceivedAt?: boolean | undefined;
checkedAt: Date;
}

View File

@@ -17,6 +17,7 @@ import Express, {
import MonitorResourceUtil from "Common/Server/Utils/Monitor/MonitorResource";
import Response from "Common/Server/Utils/Response";
import Monitor from "Common/Models/DatabaseModels/Monitor";
import logger from "Common/Server/Utils/Logger";
const router: ExpressRouter = Express.getRouter();
@@ -72,18 +73,26 @@ const processIncomingRequest: RequestHandler = async (
throw new BadDataException("Project not found");
}
const now: Date = OneUptimeDate.getCurrentDate();
const incomingRequest: IncomingMonitorRequest = {
projectId: monitor.projectId,
monitorId: new ObjectID(monitor._id.toString()),
requestHeaders: requestHeaders,
requestBody: requestBody,
incomingRequestReceivedAt: OneUptimeDate.getCurrentDate(),
incomingRequestReceivedAt: now,
onlyCheckForIncomingRequestReceivedAt: false,
requestMethod: httpMethod,
checkedAt: now,
};
// process probe response here.
await MonitorResourceUtil.monitorResource(incomingRequest);
MonitorResourceUtil.monitorResource(incomingRequest).catch((err: Error) => {
// do nothing.
// we don't want to throw error here.
// we just want to log the error.
logger.error(err);
});
return Response.sendEmptySuccessResponse(req, res);
} catch (err) {

View File

@@ -153,6 +153,7 @@ const checkHeartBeat: (monitor: Monitor) => Promise<void> = async (
onlyCheckForIncomingRequestReceivedAt: true,
monitorId: monitor.id!,
projectId: monitor.projectId!,
checkedAt: OneUptimeDate.getCurrentDate(),
};
logger.debug(