Skip to content

Commit 14fd2f9

Browse files
authored
Merge pull request #194 from vernu/dev
mark undelivered webhook notifications older than one month as aborted to prevent further retries
2 parents 3061bd8 + 540bb90 commit 14fd2f9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

api/src/webhook/webhook.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,27 @@ export class WebhookService {
570570
async checkForNotificationsToDeliver() {
571571
const now = new Date()
572572
const fiveMinutesAgo = new Date(now.getTime() - 5 * 60 * 1000)
573+
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000)
574+
575+
// Mark notifications older than one month as aborted so they are no longer retried
576+
await this.webhookNotificationModel.updateMany(
577+
{
578+
nextDeliveryAttemptAt: { $lte: fiveMinutesAgo },
579+
deliveredAt: null,
580+
deliveryAttemptCount: { $lt: 10 },
581+
deliveryAttemptAbortedAt: null,
582+
createdAt: { $lt: oneMonthAgo },
583+
},
584+
{ $set: { deliveryAttemptAbortedAt: now } },
585+
)
586+
573587
const notifications = await this.webhookNotificationModel
574588
.find({
575589
nextDeliveryAttemptAt: { $lte: fiveMinutesAgo },
576590
deliveredAt: null,
577591
deliveryAttemptCount: { $lt: 10 },
578592
deliveryAttemptAbortedAt: null,
593+
createdAt: { $gte: oneMonthAgo },
579594
})
580595
.sort({ nextDeliveryAttemptAt: 1 })
581596
.limit(200)

0 commit comments

Comments
 (0)