diff --git a/dandi/download.py b/dandi/download.py index e375a60c1..c6ba78ea2 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -1088,7 +1088,21 @@ def _check_attempts_and_sleep( attempts_allowed: int, downloaded_in_attempt: int = 0, ) -> int | None: - """Check if we should retry the download, sleep if still allowed, + """ + Check if we should retry the download, sleep if still allowed, + and return potentially adjusted 'attempts_allowed' + + :param path: Destination of the download + :param exc: Exception raised during the last download attempt + :param attempt: The index of the last download attempt + :param attempts_allowed: The number of download attempts currently allowed + :param downloaded_in_attempt: The number of bytes downloaded in the last attempt + + :returns: The number of download attempts allowed, potentially adjusted, if download + should be retried. None if download should not be retried. + Note: If download should be retried, this function sleeps before returning. + otherwise, it returns immediately. + """ and return potentially adjusted 'attempts_allowed' """ sleep_amount: float | None = None @@ -1107,7 +1121,7 @@ def _check_attempts_and_sleep( ) attempts_allowed += 1 if attempt >= attempts_allowed: - lgr.debug("%s - download failed after %d attempts: %s", path, attempt, exc) + lgr.debug("%s - download failed after %d attempts: %s", path, attempt + 1, exc) return None if exc.response is not None: if exc.response.status_code not in ( diff --git a/dandi/utils.py b/dandi/utils.py index 7084ca586..a5c3fbc16 100644 --- a/dandi/utils.py +++ b/dandi/utils.py @@ -919,7 +919,7 @@ def get_retry_after(response: requests.Response) -> Optional[int]: # and continue with "if_unparsable" sleep logic sleep_amount = None lgr.warning( - "response %d has incorrect date in Retry-After=%r: %s. " "Returning %r", + "response %d has incorrect date in Retry-After=%s: %s. Returning %r", response.status_code, retry_after, exc_ve, @@ -937,7 +937,7 @@ def get_retry_after(response: requests.Response) -> Optional[int]: elif sleep_amount < 0: sleep_amount = None lgr.warning( - "date in Retry-After=%r is in the past (current is %r). " + "date in Retry-After=%s is in the past (current is %r). " "Returning %r", retry_after, current_date, @@ -946,7 +946,7 @@ def get_retry_after(response: requests.Response) -> Optional[int]: elif sleep_amount > 7 * 24 * 60 * 60: # week sleep_amount = None lgr.warning( - "date in Retry-After=%r is over a week in the future (current is %r). " + "date in Retry-After=%s is over a week in the future (current is %r). " "Returning %r", retry_after, current_date,