-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1693 from OneUptime/stop-execution-on-incident-ack
Stop execution on incident ack
- Loading branch information
Showing
23 changed files
with
1,055 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
App/FeatureSet/Workers/Jobs/ScheduledMaintenance/SendSubscriberRemindersOnEventScheduled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import RunCron from "../../Utils/Cron"; | ||
import LIMIT_MAX from "Common/Types/Database/LimitMax"; | ||
import OneUptimeDate from "Common/Types/Date"; | ||
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"; | ||
RunCron( | ||
"ScheduledMaintenance:SendSubscriberRemindersOnEventScheduled", | ||
{ schedule: EVERY_MINUTE, runOnStartup: false }, | ||
async () => { | ||
// get all scheduled events of all the projects. | ||
const scheduledEvents: Array<ScheduledMaintenance> = | ||
await ScheduledMaintenanceService.findBy({ | ||
query: { | ||
nextSubscriberNotificationBeforeTheEventAt: QueryHelper.lessThan( | ||
OneUptimeDate.getCurrentDate(), | ||
), | ||
createdAt: QueryHelper.lessThan(OneUptimeDate.getCurrentDate()), | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
limit: LIMIT_MAX, | ||
skip: 0, | ||
select: { | ||
_id: true, | ||
title: true, | ||
description: true, | ||
startsAt: true, | ||
monitors: { | ||
_id: true, | ||
}, | ||
statusPages: { | ||
_id: true, | ||
}, | ||
sendSubscriberNotificationsOnBeforeTheEvent: true, | ||
nextSubscriberNotificationBeforeTheEventAt: true, | ||
}, | ||
}); | ||
|
||
for (const event of scheduledEvents) { | ||
const nextSubscriberNotificationAt: Date | null = | ||
ScheduledMaintenanceService.getNextTimeToNotify({ | ||
eventScheduledDate: event.startsAt!, | ||
sendSubscriberNotifiationsOn: | ||
event.sendSubscriberNotificationsOnBeforeTheEvent!, | ||
}); | ||
|
||
await ScheduledMaintenanceService.updateOneById({ | ||
id: event.id!, | ||
data: { | ||
nextSubscriberNotificationBeforeTheEventAt: | ||
nextSubscriberNotificationAt, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
}); | ||
} | ||
|
||
await ScheduledMaintenanceService.notififySubscribersOnEventScheduled( | ||
scheduledEvents, | ||
); | ||
}, | ||
); |
Oops, something went wrong.