|
1 | 1 | import asyncio |
2 | | -import random |
3 | 2 | import time |
4 | 3 | from types import TracebackType |
5 | 4 | from typing import Optional, Type, Union |
@@ -142,18 +141,14 @@ def request( |
142 | 141 | except Exception as exc: |
143 | 142 | last_exception = exc |
144 | 143 | if attempt < retry_config.max_retries and self._should_retry_exception(exc): |
145 | | - delay = retry_config.base_delay * (2 ** attempt) |
146 | | - delay = min(delay, retry_config.max_delay) |
147 | | - jitter_amount = delay * retry_config.jitter * random.random() |
148 | | - time.sleep(delay + jitter_amount) |
| 144 | + delay = self._calculate_backoff_delay(attempt, retry_config) |
| 145 | + time.sleep(delay) |
149 | 146 | continue |
150 | 147 | raise |
151 | 148 |
|
152 | | - # Should not reach here, but raise last exception if we do |
153 | 149 | if last_exception is not None: |
154 | 150 | raise last_exception |
155 | 151 |
|
156 | | - # Fallback: this should never happen |
157 | 152 | raise RuntimeError("Unexpected state in retry logic") |
158 | 153 |
|
159 | 154 |
|
@@ -279,10 +274,8 @@ async def request( |
279 | 274 | except Exception as exc: |
280 | 275 | last_exception = exc |
281 | 276 | if attempt < retry_config.max_retries and self._should_retry_exception(exc): |
282 | | - delay = retry_config.base_delay * (2 ** attempt) |
283 | | - delay = min(delay, retry_config.max_delay) |
284 | | - jitter_amount = delay * retry_config.jitter * random.random() |
285 | | - await asyncio.sleep(delay + jitter_amount) |
| 277 | + delay = self._calculate_backoff_delay(attempt, retry_config) |
| 278 | + await asyncio.sleep(delay) |
286 | 279 | continue |
287 | 280 | raise |
288 | 281 |
|
|
0 commit comments