diff --git a/src/backoff.mjs b/src/backoff.mjs index b305b29..e801157 100644 --- a/src/backoff.mjs +++ b/src/backoff.mjs @@ -2,19 +2,20 @@ export async function backoff(action, maxRetries = 6, initialDelay = 15) { let retries = 0; let delay = initialDelay; - while (true) { + while (retries < maxRetries) { try { const results = await action(); return results; } catch (e) { retries++; - console.error(e.message); - console.error(`Error. Retrying in ${delay}s. [Attempt ${retries}/${maxRetries}]`); if (retries === maxRetries) { throw new Error('Max retries exceeded.'); } + console.error(e.message); + console.error(`Error. Retrying in ${delay}s. [Attempt ${retries}/${maxRetries}]`); + await new Promise(resolve => setTimeout(resolve, 1000 * delay)); delay *= 2; } diff --git a/src/main.mjs b/src/main.mjs index 311736d..e24c6f4 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -129,4 +129,4 @@ async function runFullChallenge(systemPrompt, runs = 50, batchSize = 1) { console.log(); } -await runFullChallenge(prompt, 500, 7); +await runFullChallenge(prompt, 500, 6);