2024-06-14 11:09:53 +00:00
|
|
|
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";
|
2024-08-07 21:50:32 +00:00
|
|
|
import logger from "Common/Server/Utils/Logger";
|
|
|
|
import App from "Common/Server/Utils/StartServer";
|
|
|
|
import Telemetry from "Common/Server/Utils/Telemetry";
|
2024-06-14 11:09:53 +00:00
|
|
|
import "ejs";
|
2023-05-03 11:43:58 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const APP_NAME: string = "probe";
|
2022-01-23 19:36:47 +00:00
|
|
|
|
2024-02-27 15:37:49 +00:00
|
|
|
const init: PromiseVoidFunction = async (): Promise<void> => {
|
2024-06-14 11:09:53 +00:00
|
|
|
try {
|
2024-08-02 22:35:09 +00:00
|
|
|
// Initialize telemetry
|
|
|
|
Telemetry.init({
|
|
|
|
serviceName: APP_NAME,
|
|
|
|
});
|
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// 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
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// add default routes
|
|
|
|
await App.addDefaultRoutes();
|
2024-04-24 16:44:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
try {
|
|
|
|
// Register this probe.
|
|
|
|
await Register.registerProbe();
|
2024-03-29 16:47:56 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.debug("Probe registered");
|
2024-03-29 17:15:04 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
await Register.reportIfOffline();
|
|
|
|
} catch (err) {
|
|
|
|
logger.error("Register probe failed");
|
|
|
|
logger.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
2023-08-07 08:45:54 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
try {
|
|
|
|
let workers: number = 0;
|
2023-08-06 20:54:12 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
while (workers < PROBE_MONITORING_WORKERS) {
|
|
|
|
workers++;
|
2023-08-06 20:54:12 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const currentWorker: number = workers;
|
2023-08-07 07:57:36 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.debug(`Starting worker ${currentWorker}`);
|
2023-08-07 14:22:45 +00:00
|
|
|
|
2024-06-14 11:09:53 +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);
|
2024-06-14 11:09:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await Sleep.sleep(1000);
|
|
|
|
}
|
2023-05-02 14:29:22 +00:00
|
|
|
} catch (err) {
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.error("Starting workers failed");
|
|
|
|
logger.error(err);
|
2022-01-18 17:59:51 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
} catch (err) {
|
|
|
|
logger.error("App Init Failed:");
|
|
|
|
logger.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
2023-05-02 14:29:22 +00:00
|
|
|
};
|
2019-11-21 13:05:28 +00:00
|
|
|
|
2023-08-10 18:00:27 +00:00
|
|
|
init().catch((err: Error) => {
|
2024-06-14 11:09:53 +00:00
|
|
|
logger.error(err);
|
|
|
|
logger.error("Exiting node process");
|
|
|
|
process.exit(1);
|
2023-08-10 18:00:27 +00:00
|
|
|
});
|