From 250c3bb5c6c061f2bb04b0ecd66d146d505a693b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Wed, 25 Sep 2024 22:27:51 +0200 Subject: [PATCH] fix(auth): move redlock settings --- apps/api/src/controllers/auth.ts | 5 +---- apps/api/src/services/redlock.ts | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.ts index 73cb3d2..2298430 100644 --- a/apps/api/src/controllers/auth.ts +++ b/apps/api/src/controllers/auth.ts @@ -43,10 +43,7 @@ export async function setCachedACUC(api_key: string, acuc: AuthCreditUsageChunk const lockTTL = 10000; // 10 seconds try { - const lock = await redlock.acquire([redLockKey], lockTTL, { - retryCount: 200, - retryDelay: 100, - }); + const lock = await redlock.acquire([redLockKey], lockTTL); try { if (typeof acuc === "function") { diff --git a/apps/api/src/services/redlock.ts b/apps/api/src/services/redlock.ts index 9cbfc1f..cb27573 100644 --- a/apps/api/src/services/redlock.ts +++ b/apps/api/src/services/redlock.ts @@ -10,12 +10,9 @@ export const redlock = new Redlock( // http://redis.io/topics/distlock driftFactor: 0.01, // multiplied by lock ttl to determine drift time - // The max number of times Redlock will attempt to lock a resource - // before erroring. - retryCount: 5, - - // the time in ms between attempts - retryDelay: 100, // time in ms + retryCount: 200, + + retryDelay: 100, // the max time in ms randomly added to retries // to improve performance under high contention