Add debug logging for scheduled maintenance event processing and notifications

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

View File

@ -55,12 +55,21 @@ export class Service extends DatabaseService<Model> {
public async notififySubscribersOnEventScheduled(
scheduledEvents: Array<Model>,
): Promise<void> {
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<StatusPageResource> = [];
if (event.monitors && event.monitors.length > 0) {
@ -244,6 +253,10 @@ export class Service extends DatabaseService<Model> {
}
}
}
logger.debug(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Completed",
);
}
protected override async onBeforeUpdate(

View File

@ -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<ScheduledMaintenanceTemplate> =
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);
}
}

View File

@ -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<ScheduledMaintenance> =
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(