|
5 | 5 | from collections import Counter |
6 | 6 | from datetime import timedelta |
7 | 7 | from itertools import count |
8 | | -from typing import Union |
| 8 | +from typing import Callable, Union |
| 9 | +from warnings import warn |
9 | 10 |
|
10 | 11 | from aiohttp import client_exceptions |
11 | 12 | from tenacity import ( |
@@ -158,6 +159,14 @@ def _undocumented_error(exc: BaseException) -> bool: |
158 | 159 | ) |
159 | 160 |
|
160 | 161 |
|
| 162 | +def _deprecated(message: str, callable: Callable) -> Callable: |
| 163 | + def wrapper(factory, retry_state: RetryCallState): |
| 164 | + warn(message, DeprecationWarning, stacklevel=3) |
| 165 | + return callable(retry_state=retry_state) |
| 166 | + |
| 167 | + return wrapper |
| 168 | + |
| 169 | + |
161 | 170 | class RetryFactory: |
162 | 171 | """Factory class that builds the :class:`tenacity.AsyncRetrying` object |
163 | 172 | that defines the :ref:`default retry policy <default-retry-policy>`. |
@@ -204,14 +213,33 @@ class CustomRetryFactory(RetryFactory): |
204 | 213 | ) |
205 | 214 |
|
206 | 215 | # connection errors, other client and server failures |
| 216 | + network_error_stop = stop_after_uninterrupted_delay(15 * 60) |
207 | 217 | network_error_wait = ( |
208 | 218 | # wait from 3s to ~1m |
209 | 219 | wait_random(3, 7) + wait_random_exponential(multiplier=1, max=55) |
210 | 220 | ) |
| 221 | + |
| 222 | + download_error_stop = stop_on_download_error(max_total=4, max_permanent=2) |
211 | 223 | download_error_wait = network_error_wait |
| 224 | + |
| 225 | + temporary_download_error_stop = _deprecated( |
| 226 | + ( |
| 227 | + "The zyte_api.RetryFactory.temporary_download_error_stop() method " |
| 228 | + "is deprecated and will be removed in a future version. Use " |
| 229 | + "download_error_stop() instead." |
| 230 | + ), |
| 231 | + download_error_stop, |
| 232 | + ) |
| 233 | + temporary_download_error_wait = _deprecated( |
| 234 | + ( |
| 235 | + "The zyte_api.RetryFactory.temporary_download_error_wait() method " |
| 236 | + "is deprecated and will be removed in a future version. Use " |
| 237 | + "download_error_wait() instead." |
| 238 | + ), |
| 239 | + download_error_wait, |
| 240 | + ) |
| 241 | + |
212 | 242 | throttling_stop = stop_never |
213 | | - network_error_stop = stop_after_uninterrupted_delay(15 * 60) |
214 | | - download_error_stop = stop_on_download_error(max_total=4, max_permanent=2) |
215 | 243 |
|
216 | 244 | undocumented_error_stop = stop_on_count(2) |
217 | 245 | undocumented_error_wait = network_error_wait |
|
0 commit comments