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.pyto 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_exceptionto 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_backoffand_parse_retry_after_from_headerhelpers to extract backoff durations from JSON responses and theRetry-AfterHTTP header, supporting both integer seconds and RFC 2822 date formats.Uploader Exception Handling:
_handle_upload_exceptionto use the new retry logic, including dynamic sleep durations based on server-provided backoff andRetry-Aftervalues.Dependencies:
datetimeandemail.utilsto support parsing ofRetry-Afterheader values.