mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-23 07:42:10 +00:00
Add debug logging for scheduled maintenance event processing and notifications
This commit is contained in:
parent
21ea8d0aa2
commit
97f4d3612d
@ -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(
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user