-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Retries to the Python SDK with Exponential Backoff (#70)
* add decorator for retries * add unit test * add request_mock in pyproject.toml * remove unnecessary property from internal api client * add more unit tests * fix poetry lock file * fix linting * inherit from ApiException in InternalApiException * remove lock file * disable linting for useless-super-delegation * disable useless-super-delegation linting * allow caching image byte stream for subsequent access when file is closed * add a wrapper class to bytes * fix linting * forgotten return statement * add unit test for ByteStreamWrapper * fix linting * fix linting --------- Co-authored-by: Blaise Munyampirwa <[email protected]>
- Loading branch information
1 parent
b3b4cdc
commit bd0f361
Showing
6 changed files
with
302 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# Helper functions for checking HTTP status codes. | ||
|
||
OK_MIN = 200 | ||
OK_MAX = 299 | ||
USER_ERROR_MIN = 400 | ||
USER_ERROR_MAX = 499 | ||
|
||
# We can use range because of Python's lazy evaluation. Thus, the values | ||
# in the range are actually not generated, so we still get O(1) time complexity | ||
OK_RANGE = range(200, 300) | ||
USER_ERROR_RANGE = range(400, 500) | ||
|
||
|
||
def is_ok(status_code: int) -> bool: | ||
return OK_MIN <= status_code <= OK_MAX | ||
return status_code in OK_RANGE | ||
|
||
|
||
def is_user_error(status_code: int) -> bool: | ||
return USER_ERROR_MIN <= status_code <= USER_ERROR_MAX | ||
return status_code in USER_ERROR_RANGE |
Oops, something went wrong.