diff --git a/apps/backend/src/prisma-client.tsx b/apps/backend/src/prisma-client.tsx index 0071a291f..628c3a617 100644 --- a/apps/backend/src/prisma-client.tsx +++ b/apps/backend/src/prisma-client.tsx @@ -19,6 +19,8 @@ if (getNodeEnvironment() !== 'production') { export async function maybeTransactionWithRetry(fn: (...args: Parameters[0]>) => Promise): Promise { + const isDev = getNodeEnvironment() === 'development'; + const res = await Result.retry(async () => { try { return Result.ok(await prismaClient.$transaction(fn)); @@ -29,14 +31,17 @@ export async function maybeTransactionWithRetry(fn: (...args: Parameters( fn: (attempt: number) => Result | Promise>, - retries: number, + totalAttempts: number, { exponentialDelayBase = 1000 } = {}, ): Promise> { const errors: unknown[] = []; - for (let i = 0; i < retries; i++) { + for (let i = 0; i < totalAttempts; i++) { const res = await fn(i); if (res.status === "ok") { return Result.ok(res.data); } else { errors.push(res.error); - if (i < retries - 1) { + if (i < totalAttempts - 1) { await wait((Math.random() + 0.5) * exponentialDelayBase * (2 ** i)); } }