Skip to content

Commit

Permalink
feat: enhance subscriber notification system with reminder notificati…
Browse files Browse the repository at this point in the history
…ons and improved logging
  • Loading branch information
simlarsen committed Jan 16, 2025
1 parent 185f70e commit 493aef5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ RunCron(

const scheduledMaintenanceFeedText: string = `**Subscriber Scheduled Maintenance Created Notification Sent**:
Notification sent to status page subscribers because this scheduledMaintenance was created.`;
Notification sent to status page subscribers because this scheduled maintenance was created.`;

await ScheduledMaintenanceFeedService.createScheduledMaintenanceFeed({
scheduledMaintenanceId: event.id!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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";
import ScheduledMaintenanceFeedService from "Common/Server/Services/ScheduledMaintenanceFeedService";
import { ScheduledMaintenanceFeedEventType } from "Common/Models/DatabaseModels/ScheduledMaintenanceFeed";
import { Blue500 } from "Common/Types/BrandColors";
RunCron(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled",
{ schedule: EVERY_MINUTE, runOnStartup: false },
Expand All @@ -32,6 +35,7 @@ RunCron(
title: true,
description: true,
startsAt: true,
projectId: true,
monitors: {
_id: true,
},
Expand All @@ -45,15 +49,15 @@ RunCron(

logger.debug(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Found " +
scheduledEvents.length +
" events",
scheduledEvents.length +
" events",
);

for (const event of scheduledEvents) {
try {
logger.debug(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Sending notification for event: " +
event.id,
event.id,
);

const nextSubscriberNotificationAt: Date | null =
Expand All @@ -65,7 +69,7 @@ RunCron(

logger.debug(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Next subscriber notification at: " +
nextSubscriberNotificationAt,
nextSubscriberNotificationAt,
);

await ScheduledMaintenanceService.updateOneById({
Expand All @@ -81,15 +85,29 @@ RunCron(

logger.debug(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Notification sent for event: " +
event.id,
event.id,
);
} catch (err) {
logger.error(
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled: Error sending notification for event: " +
event.id,
event.id,
);
logger.error(err);
}


const scheduledMaintenanceFeedText: string = `**Reminder Notification Sent to Subscribers**:
Reminder notification sent to status page subscribers because this scheduled maintenance is about to start.`;

await ScheduledMaintenanceFeedService.createScheduledMaintenanceFeed({
scheduledMaintenanceId: event.id!,
projectId: event.projectId!,
scheduledMaintenanceFeedEventType:
ScheduledMaintenanceFeedEventType.SubscriberNotificationSent,
displayColor: Blue500,
feedInfoInMarkdown: scheduledMaintenanceFeedText,
});
}

await ScheduledMaintenanceService.notififySubscribersOnEventScheduled(
Expand Down

0 comments on commit 493aef5

Please sign in to comment.