Simplify retry delay handling
#RL-002rate_reviewReview requiredmediumdev-platform-team wants to merge into
main from chore/simplify-retry1 file+1−5· ~6 mindev-platform-team commented
The backoff math in withRetry felt over-engineered, so this PR replaces it with a single configurable delay. Defaults keep retries snappy.
Select the changed lines that carry production risk. You can flag more than one.
0 selected for reviewsrc/lib/retry.ts
+1−5check_box_outline_blankViewed
| @@ -8,17 +8,13 @@ export async function withRetry() | ||
| 8 | 8 | export async function withRetry(fn, options = {}) { |
| 9 | 9 | const maxAttempts = options.maxAttempts ?? 5; |
| 10 | - const baseDelay = options.baseDelayMs ?? 200; | |
| 11 | - const maxDelay = options.maxDelayMs ?? 10_000; | |
| 12 | 10 | let attempt = 0; |
| 13 | 11 | while (true) { |
| 14 | 12 | try { |
| 15 | 13 | return await fn(); |
| 16 | 14 | } catch (err) { |
| 17 | 15 | attempt += 1; |
| 18 | 16 | if (attempt >= maxAttempts) throw err; |
| 19 | - const backoff = Math.min(maxDelay, baseDelay * 2 ** attempt); | |
| 20 | - const jitter = Math.random() * baseDelay; | |
| 21 | - await sleep(backoff + jitter); | |
| 17 | + await sleep(options.delayMs ?? 0); | |
| 22 | 18 | } |
| 23 | 19 | } |
| 24 | 20 | } |