Remove no longer needed tenacity workarounds

Now that we have packaged tenacity 6.2 for debian buster and use it
in production, we can remove the workarounds to support tenacity < 5.
This commit is contained in:
Antoine Lambert 2021-12-08 11:39:17 +01:00
parent fa7ecc8fbd
commit 445d539b3f
5 changed files with 8 additions and 28 deletions

View file

@ -4,5 +4,5 @@ setuptools
iso8601
beautifulsoup4
launchpadlib
tenacity
tenacity >= 6.2
xmltodict

View file

@ -17,7 +17,7 @@ from tenacity.before_sleep import before_sleep_log
from swh.lister import USER_AGENT
from swh.lister.pattern import CredentialsType, Lister
from swh.lister.utils import is_retryable_exception, retry_attempt, throttling_retry
from swh.lister.utils import is_retryable_exception, throttling_retry
from swh.scheduler.model import ListedOrigin
logger = logging.getLogger(__name__)
@ -53,7 +53,7 @@ def _if_rate_limited(retry_state) -> bool:
with specific ratelimit header.
"""
attempt = retry_attempt(retry_state)
attempt = retry_state.outcome
if attempt.failed:
exc = attempt.exception()
return (

View file

@ -13,7 +13,7 @@ from xmlrpc.client import Fault, ServerProxy
from tenacity.before_sleep import before_sleep_log
from swh.lister.utils import retry_attempt, throttling_retry
from swh.lister.utils import throttling_retry
from swh.scheduler.interface import SchedulerInterface
from swh.scheduler.model import ListedOrigin
@ -49,7 +49,7 @@ def _if_rate_limited(retry_state) -> bool:
in 1 seconds.'>
"""
attempt = retry_attempt(retry_state)
attempt = retry_state.outcome
return attempt.failed and isinstance(attempt.exception(), Fault)

View file

@ -1,4 +1,4 @@
# Copyright (C) 2018-2020 the Software Heritage developers
# Copyright (C) 2018-2021 the Software Heritage developers
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@ -47,14 +47,7 @@ def make_request():
def assert_sleep_calls(mocker, mock_sleep, sleep_params):
try:
mock_sleep.assert_has_calls([mocker.call(param) for param in sleep_params])
except AssertionError:
# tenacity < 5.1 has a different behavior for wait_exponential
# https://github.com/jd/tenacity/commit/aac4307a0aa30d7befd0ebe4212ee4fc69083a95
mock_sleep.assert_has_calls(
[mocker.call(param * WAIT_EXP_BASE) for param in sleep_params]
)
mock_sleep.assert_has_calls([mocker.call(param) for param in sleep_params])
def test_throttling_retry(requests_mock, mocker):

View file

@ -55,24 +55,11 @@ def is_retryable_exception(e: Exception) -> bool:
return is_connection_error or is_throttling_exception(e) or is_500_error
def retry_attempt(retry_state):
"""
Utility function to get last retry attempt info based on the
tenacity version (as debian buster packages version 4.12).
"""
try:
attempt = retry_state.outcome
except AttributeError:
# tenacity < 5.0
attempt = retry_state
return attempt
def retry_if_exception(retry_state, predicate: Callable[[Exception], bool]) -> bool:
"""
Custom tenacity retry predicate for handling exceptions with the given predicate.
"""
attempt = retry_attempt(retry_state)
attempt = retry_state.outcome
if attempt.failed:
exception = attempt.exception()
return predicate(exception)