mirror of
https://github.com/vernu/textbee.git
synced 2026-05-18 21:35:12 -04:00
feat(api): mark notifications older than one month as aborted to prevent retries
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user