From 540bb9068beec0b707dfe61dec8c2fe28d5537c9 Mon Sep 17 00:00:00 2001 From: isra el Date: Thu, 5 Mar 2026 19:50:48 +0300 Subject: [PATCH] feat(api): mark notifications older than one month as aborted to prevent retries --- api/src/webhook/webhook.service.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/src/webhook/webhook.service.ts b/api/src/webhook/webhook.service.ts index 7c7aeee..5c69ea8 100644 --- a/api/src/webhook/webhook.service.ts +++ b/api/src/webhook/webhook.service.ts @@ -570,12 +570,27 @@ export class WebhookService { async checkForNotificationsToDeliver() { const now = new Date() const fiveMinutesAgo = new Date(now.getTime() - 5 * 60 * 1000) + const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000) + + // Mark notifications older than one month as aborted so they are no longer retried + await this.webhookNotificationModel.updateMany( + { + nextDeliveryAttemptAt: { $lte: fiveMinutesAgo }, + deliveredAt: null, + deliveryAttemptCount: { $lt: 10 }, + deliveryAttemptAbortedAt: null, + createdAt: { $lt: oneMonthAgo }, + }, + { $set: { deliveryAttemptAbortedAt: now } }, + ) + const notifications = await this.webhookNotificationModel .find({ nextDeliveryAttemptAt: { $lte: fiveMinutesAgo }, deliveredAt: null, deliveryAttemptCount: { $lt: 10 }, deliveryAttemptAbortedAt: null, + createdAt: { $gte: oneMonthAgo }, }) .sort({ nextDeliveryAttemptAt: 1 }) .limit(200)