Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/proxies/retry.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import traceback | import traceback | ||||
from tenacity import retry, stop_after_attempt, wait_random_exponential | from tenacity import retry, stop_after_attempt, wait_random_exponential | ||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.storage.exc import StorageArgumentException | from swh.storage.exc import StorageArgumentException | ||||
from swh.storage.interface import StorageInterface | from swh.storage.interface import StorageInterface | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
def should_retry_adding(retry_state) -> bool: | def should_retry_adding(retry_state) -> bool: | ||||
"""Retry if the error/exception is (probably) not about a caller error | """Retry if the error/exception is (probably) not about a caller error | ||||
""" | """ | ||||
try: | |||||
attempt = retry_state.outcome | attempt = retry_state.outcome | ||||
except AttributeError: | |||||
# tenacity < 5.0 | |||||
attempt = retry_state | |||||
if attempt.failed: | if attempt.failed: | ||||
error = attempt.exception() | error = attempt.exception() | ||||
if isinstance(error, StorageArgumentException): | if isinstance(error, StorageArgumentException): | ||||
# Exception is due to an invalid argument | # Exception is due to an invalid argument | ||||
return False | return False | ||||
elif isinstance(error, KeyboardInterrupt): | elif isinstance(error, KeyboardInterrupt): | ||||
return False | return False | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |