diff --git a/Common/Server/Services/ScheduledMaintenanceService.ts b/Common/Server/Services/ScheduledMaintenanceService.ts index b3d6a60bb3..385fca4d24 100644 --- a/Common/Server/Services/ScheduledMaintenanceService.ts +++ b/Common/Server/Services/ScheduledMaintenanceService.ts @@ -55,12 +55,21 @@ export class Service extends DatabaseService { public async notififySubscribersOnEventScheduled( scheduledEvents: Array, ): Promise { + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Running", + ); + const host: Hostname = await DatabaseConfig.getHost(); const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol(); for (const event of scheduledEvents) { // get status page resources from monitors. + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Sending notification for event: " + + event.id, + ); + let statusPageResources: Array = []; if (event.monitors && event.monitors.length > 0) { @@ -244,6 +253,10 @@ export class Service extends DatabaseService { } } } + + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Completed", + ); } protected override async onBeforeUpdate( diff --git a/Worker/Jobs/ScheduledMaintenance/ScheduleRecurringEvents.ts b/Worker/Jobs/ScheduledMaintenance/ScheduleRecurringEvents.ts index d964c86bbc..bc02c2a3c8 100644 --- a/Worker/Jobs/ScheduledMaintenance/ScheduleRecurringEvents.ts +++ b/Worker/Jobs/ScheduledMaintenance/ScheduleRecurringEvents.ts @@ -21,6 +21,8 @@ RunCron( "ScheduledMaintenance:ScheduleRecurringEvents", { schedule: EVERY_MINUTE, runOnStartup: false }, async () => { + logger.debug("ScheduledMaintenance:ScheduleRecurringEvents Running"); + // get all scheduled events of all the projects. const recurringTemplates: Array = await ScheduledMaintenanceTemplateService.findBy({ @@ -61,6 +63,10 @@ RunCron( for (const recurringTemplate of recurringTemplates) { try { + logger.debug( + `ScheduledMaintenance:ScheduleRecurringEvents: Updating event: ${recurringTemplate.id}`, + ); + if (recurringTemplate.recurringInterval === undefined) { continue; } @@ -209,7 +215,14 @@ RunCron( }, }); } + + logger.debug( + `ScheduledMaintenance:ScheduleRecurringEvents: Created event: ${scheduledMaintenanceEvent.id}`, + ); } catch (e) { + logger.error( + `ScheduledMaintenance:ScheduleRecurringEvents: Error creating event for template: ${recurringTemplate.id}`, + ); logger.error(e); } } diff --git a/Worker/Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled.ts b/Worker/Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled.ts index 2af0102aa1..ed171b098a 100644 --- a/Worker/Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled.ts +++ b/Worker/Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled.ts @@ -5,10 +5,14 @@ import { EVERY_MINUTE } from "Common/Utils/CronTime"; import QueryHelper from "Common/Server/Types/Database/QueryHelper"; import ScheduledMaintenance from "Common/Models/DatabaseModels/ScheduledMaintenance"; import ScheduledMaintenanceService from "Common/Server/Services/ScheduledMaintenanceService"; +import logger from "Common/Server/Utils/Logger"; RunCron( "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled", { schedule: EVERY_MINUTE, runOnStartup: false }, async () => { + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Running", + ); // get all scheduled events of all the projects. const scheduledEvents: Array = await ScheduledMaintenanceService.findBy({ @@ -39,24 +43,53 @@ RunCron( }, }); + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Found " + + scheduledEvents.length + + " events", + ); + for (const event of scheduledEvents) { - const nextSubscriberNotificationAt: Date | null = - ScheduledMaintenanceService.getNextTimeToNotify({ - eventScheduledDate: event.startsAt!, - sendSubscriberNotifiationsOn: - event.sendSubscriberNotificationsOnBeforeTheEvent!, + try { + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Sending notification for event: " + + event.id, + ); + + const nextSubscriberNotificationAt: Date | null = + ScheduledMaintenanceService.getNextTimeToNotify({ + eventScheduledDate: event.startsAt!, + sendSubscriberNotifiationsOn: + event.sendSubscriberNotificationsOnBeforeTheEvent!, + }); + + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Next subscriber notification at: " + + nextSubscriberNotificationAt, + ); + + await ScheduledMaintenanceService.updateOneById({ + id: event.id!, + data: { + nextSubscriberNotificationBeforeTheEventAt: + nextSubscriberNotificationAt, + }, + props: { + isRoot: true, + }, }); - await ScheduledMaintenanceService.updateOneById({ - id: event.id!, - data: { - nextSubscriberNotificationBeforeTheEventAt: - nextSubscriberNotificationAt, - }, - props: { - isRoot: true, - }, - }); + logger.debug( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Notification sent for event: " + + event.id, + ); + } catch (err) { + logger.error( + "ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Error sending notification for event: " + + event.id, + ); + logger.error(err); + } } await ScheduledMaintenanceService.notififySubscribersOnEventScheduled(