diff --git a/src/backoff.mjs b/src/backoff.mjs index 55f44b0..38bea93 100644 --- a/src/backoff.mjs +++ b/src/backoff.mjs @@ -2,21 +2,21 @@ export async function backoff(action, maxRetries = 6, initialDelay = 15) { let retries = 0; let delay = initialDelay; - while (retries < maxRetries) { + while (true) { try { const results = await action(); return results; } catch (e) { - if (retries === maxRetries) { - throw new Error('Max retries exceeded.'); - } - retries++; console.error(e.message); - console.error(`Error. Retrying in ${delay}s. [Attempt ${retries}/${maxRetries}]`); - await new Promise(resolve => setTimeout(resolve, 1000 * delay)); - delay *= 2; + if (retries <= maxRetries) { + console.error(`Error. Retrying in ${delay}s. [Attempt ${retries}/${maxRetries}]`); + await new Promise(resolve => setTimeout(resolve, 1000 * delay)); + delay *= 2; + } else { + throw new Error('Max retries exceeded.'); + } } } } \ No newline at end of file diff --git a/src/main.mjs b/src/main.mjs index 096ae52..311736d 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, 10); +await runFullChallenge(prompt, 500, 7);