14 """This contains common retrying helpers (retryers).
16 We use tenacity as a general-purpose retrying library.
18 > It [tenacity] originates from a fork of retrying which is sadly no
19 > longer maintained. Tenacity isn’t api compatible with retrying but >
20 > adds significant new functionality and fixes a number of longstanding bugs.
21 > - https://tenacity.readthedocs.io/en/latest/index.html
25 from typing
import Any, Optional, Sequence
29 retryers_logger = logging.getLogger(__name__)
31 timedelta = datetime.timedelta
32 Retrying = tenacity.Retrying
33 RetryError = tenacity.RetryError
34 _after_log = tenacity.after_log
35 _before_sleep_log = tenacity.before_sleep_log
36 _retry_if_exception_type = tenacity.retry_if_exception_type
37 _stop_after_attempt = tenacity.stop_after_attempt
38 _stop_after_delay = tenacity.stop_after_delay
39 _stop_any = tenacity.stop_any
40 _wait_exponential = tenacity.wait_exponential
41 _wait_fixed = tenacity.wait_fixed
46 if retry_on_exceptions
is None:
47 retry_on_exceptions = (Exception,)
56 retry_on_exceptions: Optional[Sequence[Any]] =
None,
57 logger: Optional[logging.Logger] =
None,
58 log_level: Optional[int] = logging.DEBUG) -> Retrying:
60 logger = retryers_logger
62 log_level = logging.DEBUG
65 max=wait_max.total_seconds()),
71 wait_fixed: timedelta,
73 timeout: Optional[timedelta] =
None,
74 retry_on_exceptions: Optional[Sequence[Any]] =
None,
75 logger: Optional[logging.Logger] =
None,
76 log_level: Optional[int] = logging.DEBUG) -> Retrying:
78 logger = retryers_logger
80 log_level = logging.DEBUG
81 if attempts < 1
and timeout
is None:
82 raise ValueError(
'The number of attempts or the timeout must be set')
86 if timeout
is not None: