|
|
@ -157,14 +157,15 @@ export class WebhookService { |
|
|
webhookNotification: WebhookNotificationDocument, |
|
|
webhookNotification: WebhookNotificationDocument, |
|
|
) { |
|
|
) { |
|
|
const now = new Date() |
|
|
const now = new Date() |
|
|
|
|
|
const webhookSubscriptionId = webhookNotification.webhookSubscription |
|
|
|
|
|
|
|
|
const webhookSubscription = await this.webhookSubscriptionModel.findById( |
|
|
const webhookSubscription = await this.webhookSubscriptionModel.findById( |
|
|
webhookNotification.webhookSubscription, |
|
|
|
|
|
|
|
|
webhookSubscriptionId, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
if (!webhookSubscription) { |
|
|
if (!webhookSubscription) { |
|
|
console.log( |
|
|
console.log( |
|
|
`Webhook subscription not found for ${webhookNotification._id}`, |
|
|
|
|
|
|
|
|
`Webhook subscription not found for ${webhookSubscriptionId}`, |
|
|
) |
|
|
) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -213,6 +214,10 @@ export class WebhookService { |
|
|
webhookNotification.deliveryAttemptCount, |
|
|
webhookNotification.deliveryAttemptCount, |
|
|
) |
|
|
) |
|
|
await webhookNotification.save() |
|
|
await webhookNotification.save() |
|
|
|
|
|
|
|
|
|
|
|
webhookSubscription.deliveryFailureCount += 1 |
|
|
|
|
|
webhookSubscription.lastDeliveryFailureAt = now |
|
|
|
|
|
|
|
|
} finally { |
|
|
} finally { |
|
|
webhookSubscription.deliveryAttemptCount += 1 |
|
|
webhookSubscription.deliveryAttemptCount += 1 |
|
|
await webhookSubscription.save() |
|
|
await webhookSubscription.save() |
|
|
@ -244,7 +249,9 @@ export class WebhookService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Check for notifications that need to be delivered every 3 minutes
|
|
|
// Check for notifications that need to be delivered every 3 minutes
|
|
|
@Cron('0 */3 * * * *') |
|
|
|
|
|
|
|
|
@Cron('0 */3 * * * *', { |
|
|
|
|
|
disabled: process.env.NODE_ENV !== 'production' |
|
|
|
|
|
}) |
|
|
async checkForNotificationsToDeliver() { |
|
|
async checkForNotificationsToDeliver() { |
|
|
const now = new Date() |
|
|
const now = new Date() |
|
|
const notifications = await this.webhookNotificationModel |
|
|
const notifications = await this.webhookNotificationModel |
|
|
|