From e845eda898ed51e266c34d57f4d7b5ed15882a0e Mon Sep 17 00:00:00 2001 From: Natty Date: Sun, 17 Nov 2024 20:04:03 +0100 Subject: [PATCH] Delivery backoff tweaks --- packages/backend/src/queue/initialize.ts | 5 +++++ packages/backend/src/queue/processors/deliver.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/queue/initialize.ts b/packages/backend/src/queue/initialize.ts index 0686fe9cd3..a6164d50fb 100644 --- a/packages/backend/src/queue/initialize.ts +++ b/packages/backend/src/queue/initialize.ts @@ -33,6 +33,11 @@ function apBackoff(attemptsMade: number, err: Error) { const baseDelay = 60 * 1000; // 1min const maxBackoff = 8 * 60 * 60 * 1000; // 8hours let backoff = (Math.pow(2, attemptsMade) - 1) * baseDelay; + + if (err?.message?.startsWith("RetriableLater")) { + backoff += (Math.pow(1.5, attemptsMade) - 1) * baseDelay * 10 * attemptsMade; + } + backoff = Math.min(backoff, maxBackoff); backoff += Math.round(backoff * Math.random() * 0.2); return backoff; diff --git a/packages/backend/src/queue/processors/deliver.ts b/packages/backend/src/queue/processors/deliver.ts index 4021903045..70effb871d 100644 --- a/packages/backend/src/queue/processors/deliver.ts +++ b/packages/backend/src/queue/processors/deliver.ts @@ -76,8 +76,8 @@ export default async (job: Bull.Job) => { // 5xx etc. throw new Error(`${err.retry_class}: ${err.message}`); - } else { - throw res; } + + throw res; } };