Skip to content

Commit

Permalink
chore: reduce parallel, patch backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjlewis committed Apr 15, 2024
1 parent ceeabb1 commit f811c51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/backoff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ async function runFullChallenge(systemPrompt, runs = 50, batchSize = 1) {
console.log();
}

await runFullChallenge(prompt, 500, 7);
await runFullChallenge(prompt, 500, 6);

0 comments on commit f811c51

Please sign in to comment.