oneuptime/Probe/Jobs/Alive.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

import { INGESTOR_URL } from "../Config";
import Register from "../Services/Register";
import ProbeAPIRequest from "../Utils/ProbeAPIRequest";
import URL from "Common/Types/API/URL";
import API from "Common/Utils/API";
import { EVERY_MINUTE } from "Common/Utils/CronTime";
import LocalCache from "CommonServer/Infrastructure/LocalCache";
import BasicCron from "CommonServer/Utils/BasicCron";
import logger from "CommonServer/Utils/Logger";
2023-05-03 11:43:58 +00:00
2024-02-27 18:29:29 +00:00
BasicCron({
jobName: "Basic:Alive",
options: {
schedule: EVERY_MINUTE,
runOnStartup: false,
},
runFunction: async () => {
logger.debug("Checking if probe is alive...");
2023-09-22 11:49:51 +00:00
const probeId: string | undefined = LocalCache.getString(
"PROBE",
"PROBE_ID",
);
2023-09-22 11:49:51 +00:00
if (!probeId) {
logger.warn(
"Probe is not registered yet. Skipping alive check. Trying to register probe again...",
);
await Register.registerProbe();
return;
}
2023-05-03 11:43:58 +00:00
logger.debug("Probe ID: " + probeId.toString());
2023-10-12 19:04:37 +00:00
await API.post(
URL.fromString(INGESTOR_URL.toString()).addRoute("/alive"),
ProbeAPIRequest.getDefaultRequestBody(),
);
},
2024-02-27 18:29:29 +00:00
});