Skip to content

Commit

Permalink
add code review
Browse files Browse the repository at this point in the history
  • Loading branch information
asledz authored and Anita Śledź committed Oct 5, 2023
1 parent 8643b24 commit 8c7e289
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
16 changes: 11 additions & 5 deletions src/neptune/common/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__all__ = ["with_api_exceptions_handler"]
__all__ = ["with_api_exceptions_handler", "get_retry_from_headers_or_default"]

import itertools
import logging
Expand Down Expand Up @@ -47,10 +47,7 @@
NeptuneSSLVerificationError,
Unauthorized,
)
from neptune.common.utils import (
get_retry_from_headers_or_default,
reset_internal_ssl_state,
)
from neptune.common.utils import reset_internal_ssl_state

_logger = logging.getLogger(__name__)

Expand All @@ -59,6 +56,15 @@
retries_timeout = int(os.getenv(NEPTUNE_RETRIES_TIMEOUT_ENV, "60"))


def get_retry_from_headers_or_default(headers, retry_count):
try:
return (
int(headers["retry-after"][0]) if "retry-after" in headers else 2 ** min(MAX_RETRY_MULTIPLIER, retry_count)
)
except Exception:
return min(2 ** min(MAX_RETRY_MULTIPLIER, retry_count), MAX_RETRY_TIME)


def with_api_exceptions_handler(func):
def wrapper(*args, **kwargs):
ssl_error_occurred = False
Expand Down
13 changes: 0 additions & 13 deletions src/neptune/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,3 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb):
pass


MAX_RETRY_TIME = 30
MAX_RETRY_MULTIPLIER = 10


def get_retry_from_headers_or_default(headers, retry_count):
try:
return (
int(headers["retry-after"][0]) if "retry-after" in headers else 2 ** min(MAX_RETRY_MULTIPLIER, retry_count)
)
except Exception:
return min(2 ** min(MAX_RETRY_MULTIPLIER, retry_count), MAX_RETRY_TIME)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from urllib3.exceptions import NewConnectionError

from neptune.common.utils import get_retry_from_headers_or_default
from neptune.common.backends.utils import get_retry_from_headers_or_default
from neptune.legacy.api_exceptions import (
ConnectionLost,
Forbidden,
Expand Down

0 comments on commit 8c7e289

Please sign in to comment.