Skip to content

Commit

Permalink
better loggin in maintenance [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Feb 13, 2025
1 parent 2b1b015 commit e1fd8a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/utils/retry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DEFAULT_BATCH_SIZE = 30;
const DEFAULT_RETRY_SLEEP_MS = 1000;
const DEFAULT_RETRY_SLEEP_MS = 10000;
const DEFAULT_MAX_RETRY_ATTEMPTS = 3;

// calls processor function on each item of items, in parallel, up to batchSize items at a time
Expand Down Expand Up @@ -36,6 +36,7 @@ export async function processQueue<T, S>(
// Helper function to implement retry logic
export async function withRetry<T>(
operation: () => Promise<T>,
caption: string = "operation",
maxAttempts: number = DEFAULT_MAX_RETRY_ATTEMPTS,
delayMs: number = DEFAULT_RETRY_SLEEP_MS,
): Promise<T> {
Expand All @@ -48,7 +49,9 @@ export async function withRetry<T>(
lastError = error;
if (attempt < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, delayMs));
console.log(`Retrying... (attempt ${attempt + 1}/${maxAttempts})`);
console.log(
`Retrying ${caption} ... (attempt ${attempt + 1}/${maxAttempts})`,
);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/validate_urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function testURL({
}
throw new Error(err);
}
});
}, url);
} catch (e) {
// Only add warning/error after all retries have failed
console.error(` ${networkId} - exception at ${url}: ${e.message}`);
Expand Down Expand Up @@ -70,7 +70,7 @@ async function testAPI({
` ${networkId} - URL returned an error, which is probably fine: ${url} - ${response.status}`,
);
}
});
}, url);
} catch (e) {
// Only add warning after all retries have failed
console.error(` ${networkId} - exception at ${url}: ${e.message}`);
Expand Down Expand Up @@ -124,7 +124,7 @@ async function testRpc({
if (genesisHash?.toLowerCase() !== network.genesis?.hash.toLowerCase()) {
throw new Error("mismatched genesis hash");
}
});
}, url);
} catch (e) {
let errorMessage = "unknown error";
if (e instanceof Error) {
Expand Down

0 comments on commit e1fd8a8

Please sign in to comment.