From 1fa939f47cd3ec082c891eb59081ba5cca1c5b2c Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Tue, 2 Apr 2024 13:18:42 -0300 Subject: [PATCH] api: Retry processing recording up to 4 times (#2119) --- packages/api/src/webhooks/cannon.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/api/src/webhooks/cannon.ts b/packages/api/src/webhooks/cannon.ts index 741dcec788..3fb42dcc8a 100644 --- a/packages/api/src/webhooks/cannon.ts +++ b/packages/api/src/webhooks/cannon.ts @@ -467,7 +467,7 @@ export default class WebhookCannon { async handleRecordingWaitingChecks( sessionId: string, - isRetry = false + attempt = 1 ): Promise { const session = await db.session.get(sessionId, { useReplica: false, @@ -482,13 +482,13 @@ export default class WebhookCannon { throw new UnprocessableEntityError("Session is unused"); } if (lastSeen > activeThreshold) { - if (isRetry) { + if (attempt >= 5) { throw new UnprocessableEntityError("Session is still active"); } - // there was an update after the delayed event was sent, so sleep a few - // secs (up to USER_SESSION_TIMEOUT) and re-check if it actually stopped. + // there was an update after the delayed event was sent, so sleep a few secs + // (up to 5s + USER_SESSION_TIMEOUT) and re-check if it actually stopped. await sleep(5000 + (lastSeen - activeThreshold)); - return this.handleRecordingWaitingChecks(sessionId, true); + return this.handleRecordingWaitingChecks(sessionId, attempt + 1); } // if we got to this point, it means we're confident this session is inactive