fix: handle HTTP 429 as retriable errors #780
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request enhances the upload retry logic in
mapillary_tools/uploader.py
to handle rate-limiting and server errors more robustly. The main improvements include more precise parsing of HTTP response headers and error bodies to determine retryability and wait times, and refactoring the retry logic to support these changes.Retry Logic Improvements:
_is_retriable_exception
to return a tuple(retriable: bool, retry_after_sec: int)
instead of just a boolean, enabling more granular control over retry timing based on server responses and headers. Added comprehensive docstring and test examples._parse_backoff
and_parse_retry_after_from_header
helpers to extract backoff durations from JSON responses and theRetry-After
HTTP header, supporting both integer seconds and RFC 2822 date formats.Uploader Exception Handling:
_handle_upload_exception
to use the new retry logic, including dynamic sleep durations based on server-provided backoff andRetry-After
values.Dependencies:
datetime
andemail.utils
to support parsing ofRetry-After
header values.