Add debug logging for worker initialization and heartbeat checks

This commit is contained in:
Simon Larsen 2024-09-20 11:07:35 +01:00
parent af177d0569
commit 21ea8d0aa2
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
3 changed files with 74 additions and 45 deletions

View File

@ -14,11 +14,15 @@ const APP_NAME: string = "worker";
const init: PromiseVoidFunction = async (): Promise<void> => { const init: PromiseVoidFunction = async (): Promise<void> => {
try { try {
logger.debug("Initializing Worker");
// Initialize telemetry // Initialize telemetry
Telemetry.init({ Telemetry.init({
serviceName: APP_NAME, serviceName: APP_NAME,
}); });
logger.debug("Telemetry initialized");
const statusCheck: PromiseVoidFunction = async (): Promise<void> => { const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
// Check the status of infrastructure components // Check the status of infrastructure components
return await InfrastructureStatus.checkStatus({ return await InfrastructureStatus.checkStatus({
@ -37,27 +41,43 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
}, },
}); });
logger.debug("App initialized");
// Connect to Postgres database // Connect to Postgres database
await PostgresAppInstance.connect(); await PostgresAppInstance.connect();
logger.debug("Postgres connected");
// Connect to Redis // Connect to Redis
await Redis.connect(); await Redis.connect();
logger.debug("Redis connected");
// Connect to Clickhouse database // Connect to Clickhouse database
await ClickhouseAppInstance.connect( await ClickhouseAppInstance.connect(
ClickhouseAppInstance.getDatasourceOptions(), ClickhouseAppInstance.getDatasourceOptions(),
); );
logger.debug("Clickhouse connected");
// Initialize real-time functionalities // Initialize real-time functionalities
await Realtime.init(); await Realtime.init();
logger.debug("Realtime initialized");
// Initialize home routes at the end since it has a catch-all route // Initialize home routes at the end since it has a catch-all route
await WorkerRoutes.init(); await WorkerRoutes.init();
logger.debug("Routes initialized");
// Add default routes to the app // Add default routes to the app
await App.addDefaultRoutes(); await App.addDefaultRoutes();
logger.debug("Default routes added");
logger.info("Worker Initialized Successfully");
} catch (err) { } catch (err) {
logger.error("App Init Failed:"); logger.error("Worker Init Failed:");
logger.error(err); logger.error(err);
throw err; throw err;
} }

View File

@ -101,6 +101,10 @@ RunCron(
continue; continue;
} }
logger.debug(
`Updating incoming request monitor heartbeat checked at: ${monitor.id?.toString()}`,
);
await MonitorService.updateOneById({ await MonitorService.updateOneById({
id: monitor.id!, id: monitor.id!,
data: { data: {

View File

@ -15,6 +15,7 @@ RunCron(
"ServerMonitor:CheckOnlineStatus", "ServerMonitor:CheckOnlineStatus",
{ schedule: EVERY_MINUTE, runOnStartup: false }, { schedule: EVERY_MINUTE, runOnStartup: false },
async () => { async () => {
try {
const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2); const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2);
const serverMonitors: Array<Monitor> = await MonitorService.findBy({ const serverMonitors: Array<Monitor> = await MonitorService.findBy({
@ -64,6 +65,10 @@ RunCron(
logger.error(error); logger.error(error);
} }
} }
} catch (error) {
logger.error("Error in ServerMonitor:CheckOnlineStatus");
logger.error(error);
}
}, },
); );