Formula for computing the current backoff :rtype: float
(self)
| 307 | return new_retries |
| 308 | |
| 309 | def get_backoff_time(self) -> float: |
| 310 | """Formula for computing the current backoff |
| 311 | |
| 312 | :rtype: float |
| 313 | """ |
| 314 | # We want to consider only the last consecutive errors sequence (Ignore redirects). |
| 315 | consecutive_errors_len = len( |
| 316 | list( |
| 317 | takewhile(lambda x: x.redirect_location is None, reversed(self.history)) |
| 318 | ) |
| 319 | ) |
| 320 | if consecutive_errors_len <= 1: |
| 321 | return 0 |
| 322 | |
| 323 | backoff_value = self.backoff_factor * (2 ** (consecutive_errors_len - 1)) |
| 324 | if self.backoff_jitter != 0.0: |
| 325 | backoff_value += random.random() * self.backoff_jitter |
| 326 | return float(max(0, min(self.backoff_max, backoff_value))) |
| 327 | |
| 328 | def parse_retry_after(self, retry_after: str) -> float: |
| 329 | seconds: float |
no outgoing calls