diff --git a/Worker/Index.ts b/Worker/Index.ts index 6fe05fb258..5a6ced12c4 100644 --- a/Worker/Index.ts +++ b/Worker/Index.ts @@ -14,11 +14,15 @@ const APP_NAME: string = "worker"; const init: PromiseVoidFunction = async (): Promise => { try { + logger.debug("Initializing Worker"); + // Initialize telemetry Telemetry.init({ serviceName: APP_NAME, }); + logger.debug("Telemetry initialized"); + const statusCheck: PromiseVoidFunction = async (): Promise => { // Check the status of infrastructure components return await InfrastructureStatus.checkStatus({ @@ -37,27 +41,43 @@ const init: PromiseVoidFunction = async (): Promise => { }, }); + logger.debug("App initialized"); + // Connect to Postgres database await PostgresAppInstance.connect(); + logger.debug("Postgres connected"); + // Connect to Redis await Redis.connect(); + logger.debug("Redis connected"); + // Connect to Clickhouse database await ClickhouseAppInstance.connect( ClickhouseAppInstance.getDatasourceOptions(), ); + logger.debug("Clickhouse connected"); + // Initialize real-time functionalities await Realtime.init(); + logger.debug("Realtime initialized"); + // Initialize home routes at the end since it has a catch-all route await WorkerRoutes.init(); + logger.debug("Routes initialized"); + // Add default routes to the app await App.addDefaultRoutes(); + + logger.debug("Default routes added"); + + logger.info("Worker Initialized Successfully"); } catch (err) { - logger.error("App Init Failed:"); + logger.error("Worker Init Failed:"); logger.error(err); throw err; } diff --git a/Worker/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts b/Worker/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts index 876f8f7d88..be1cfc6c39 100644 --- a/Worker/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts +++ b/Worker/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts @@ -101,6 +101,10 @@ RunCron( continue; } + logger.debug( + `Updating incoming request monitor heartbeat checked at: ${monitor.id?.toString()}`, + ); + await MonitorService.updateOneById({ id: monitor.id!, data: { diff --git a/Worker/Jobs/ServerMonitor/CheckOnlineStatus.ts b/Worker/Jobs/ServerMonitor/CheckOnlineStatus.ts index 7aebb52292..ef2c2fe84a 100644 --- a/Worker/Jobs/ServerMonitor/CheckOnlineStatus.ts +++ b/Worker/Jobs/ServerMonitor/CheckOnlineStatus.ts @@ -15,54 +15,59 @@ RunCron( "ServerMonitor:CheckOnlineStatus", { schedule: EVERY_MINUTE, runOnStartup: false }, async () => { - const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2); + try { + const twoMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(2); - const serverMonitors: Array = await MonitorService.findBy({ - query: { - monitorType: MonitorType.Server, - serverMonitorRequestReceivedAt: - QueryHelper.lessThanEqualToOrNull(twoMinsAgo), - }, - props: { - isRoot: true, - }, - select: { - _id: true, - monitorSteps: true, - serverMonitorRequestReceivedAt: true, - createdAt: true, - }, - limit: LIMIT_MAX, - skip: 0, - }); + const serverMonitors: Array = await MonitorService.findBy({ + query: { + monitorType: MonitorType.Server, + serverMonitorRequestReceivedAt: + QueryHelper.lessThanEqualToOrNull(twoMinsAgo), + }, + props: { + isRoot: true, + }, + select: { + _id: true, + monitorSteps: true, + serverMonitorRequestReceivedAt: true, + createdAt: true, + }, + limit: LIMIT_MAX, + skip: 0, + }); - for (const monitor of serverMonitors) { - try { - if (!monitor.monitorSteps) { - continue; + for (const monitor of serverMonitors) { + try { + if (!monitor.monitorSteps) { + continue; + } + + const processRequest: boolean = shouldProcessRequest(monitor); + + if (!processRequest) { + continue; + } + + const serverMonitorResponse: ServerMonitorResponse = { + monitorId: monitor.id!, + onlyCheckRequestReceivedAt: true, + requestReceivedAt: + monitor.serverMonitorRequestReceivedAt || monitor.createdAt!, + hostname: "", + }; + + await MonitorResourceUtil.monitorResource(serverMonitorResponse); + } catch (error) { + logger.error( + `Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`, + ); + logger.error(error); } - - const processRequest: boolean = shouldProcessRequest(monitor); - - if (!processRequest) { - continue; - } - - const serverMonitorResponse: ServerMonitorResponse = { - monitorId: monitor.id!, - onlyCheckRequestReceivedAt: true, - requestReceivedAt: - monitor.serverMonitorRequestReceivedAt || monitor.createdAt!, - hostname: "", - }; - - await MonitorResourceUtil.monitorResource(serverMonitorResponse); - } catch (error) { - logger.error( - `Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`, - ); - logger.error(error); } + } catch (error) { + logger.error("Error in ServerMonitor:CheckOnlineStatus"); + logger.error(error); } }, );