2023-05-02 14:29:22 +00:00
|
|
|
import 'ejs';
|
2022-04-10 21:57:14 +00:00
|
|
|
import logger from 'CommonServer/Utils/Logger';
|
2023-05-02 14:29:22 +00:00
|
|
|
import App from 'CommonServer/Utils/StartServer';
|
2023-05-03 10:54:25 +00:00
|
|
|
import Register from './Services/Register';
|
2024-02-27 15:56:47 +00:00
|
|
|
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
|
2023-05-03 11:43:58 +00:00
|
|
|
import './Jobs/Alive';
|
2023-08-06 20:54:12 +00:00
|
|
|
import FetchListAndProbe from './Jobs/Monitor/FetchList';
|
|
|
|
import { PROBE_MONITORING_WORKERS } from './Config';
|
2023-08-07 14:22:45 +00:00
|
|
|
import Sleep from 'Common/Types/Sleep';
|
2023-05-03 11:43:58 +00:00
|
|
|
|
2023-05-02 14:29:22 +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> => {
|
2023-05-02 14:29:22 +00:00
|
|
|
try {
|
|
|
|
// init the app
|
|
|
|
await App(APP_NAME);
|
2023-05-02 20:46:00 +00:00
|
|
|
|
2023-08-07 08:45:54 +00:00
|
|
|
try {
|
|
|
|
// Register this probe.
|
|
|
|
await Register.registerProbe();
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Register probe failed');
|
|
|
|
logger.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let workers: number = 0;
|
|
|
|
|
|
|
|
while (workers < PROBE_MONITORING_WORKERS) {
|
|
|
|
workers++;
|
2023-08-06 20:54:12 +00:00
|
|
|
|
2023-08-07 08:45:54 +00:00
|
|
|
const currentWorker: number = workers;
|
2023-08-06 20:54:12 +00:00
|
|
|
|
2023-08-07 08:45:54 +00:00
|
|
|
logger.info(`Starting worker ${currentWorker}`);
|
2023-08-07 07:57:36 +00:00
|
|
|
|
2023-08-07 08:45:54 +00:00
|
|
|
new FetchListAndProbe('Worker ' + currentWorker)
|
|
|
|
.run()
|
|
|
|
.catch((err: any) => {
|
|
|
|
logger.error(`Worker ${currentWorker} failed: `);
|
|
|
|
logger.error(err);
|
|
|
|
});
|
2023-08-07 14:22:45 +00:00
|
|
|
|
|
|
|
await Sleep.sleep(1000);
|
2023-08-07 08:45:54 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Starting workers failed');
|
|
|
|
logger.error(err);
|
2023-08-06 20:54:12 +00:00
|
|
|
}
|
2023-05-02 14:29:22 +00:00
|
|
|
} catch (err) {
|
|
|
|
logger.error('App Init Failed:');
|
|
|
|
logger.error(err);
|
2023-10-04 18:22:25 +00:00
|
|
|
throw err;
|
2022-01-18 17:59:51 +00:00
|
|
|
}
|
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) => {
|
|
|
|
logger.error(err);
|
2023-10-04 18:22:25 +00:00
|
|
|
logger.info('Exiting node process');
|
2023-09-27 19:48:50 +00:00
|
|
|
process.exit(1);
|
2023-08-10 18:00:27 +00:00
|
|
|
});
|