oneuptime/Probe/Index.ts

83 lines
2.0 KiB
TypeScript
Raw Normal View History

import { PROBE_MONITORING_WORKERS } from "./Config";
import "./Jobs/Alive";
import FetchListAndProbe from "./Jobs/Monitor/FetchList";
import Register from "./Services/Register";
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
import Sleep from "Common/Types/Sleep";
import logger from "Common/Server/Utils/Logger";
import App from "Common/Server/Utils/StartServer";
import Telemetry from "Common/Server/Utils/Telemetry";
import "ejs";
2023-05-03 11:43:58 +00:00
const APP_NAME: string = "probe";
2022-01-23 19:36:47 +00:00
const init: PromiseVoidFunction = async (): Promise<void> => {
try {
// Initialize telemetry
Telemetry.init({
serviceName: APP_NAME,
});
// init the app
await App.init({
appName: APP_NAME,
port: undefined,
isFrontendApp: false,
statusOptions: {
liveCheck: async () => {},
readyCheck: async () => {},
},
});
2023-05-02 20:46:00 +00:00
// add default routes
await App.addDefaultRoutes();
try {
// Register this probe.
await Register.registerProbe();
logger.debug("Probe registered");
await Register.reportIfOffline();
} catch (err) {
logger.error("Register probe failed");
logger.error(err);
throw err;
}
2023-08-07 08:45:54 +00:00
try {
let workers: number = 0;
2023-08-06 20:54:12 +00:00
while (workers < PROBE_MONITORING_WORKERS) {
workers++;
2023-08-06 20:54:12 +00:00
const currentWorker: number = workers;
2023-08-07 07:57:36 +00:00
logger.debug(`Starting worker ${currentWorker}`);
2023-08-07 14:22:45 +00:00
new FetchListAndProbe("Worker " + currentWorker)
.run()
.catch((err: any) => {
logger.error(`Worker ${currentWorker} failed: `);
2023-08-07 08:45:54 +00:00
logger.error(err);
});
await Sleep.sleep(1000);
}
2023-05-02 14:29:22 +00:00
} catch (err) {
logger.error("Starting workers failed");
logger.error(err);
2022-01-18 17:59:51 +00:00
}
} catch (err) {
logger.error("App Init Failed:");
logger.error(err);
throw err;
}
2023-05-02 14:29:22 +00:00
};
2023-08-10 18:00:27 +00:00
init().catch((err: Error) => {
logger.error(err);
logger.error("Exiting node process");
process.exit(1);
2023-08-10 18:00:27 +00:00
});