-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): implement the retry functionality
Add a proper implementation of the retry functionality making the client more resilient when faced with IO Errors.
- Loading branch information
1 parent
9383fb2
commit b258a6e
Showing
17 changed files
with
836 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .exceptions import RetryError | ||
from .retry import Retry, if_exception_type_factory, if_idr_exception | ||
from .setting_initializers import RetryInitializer | ||
|
||
__all__ = [ | ||
"Retry", | ||
"RetryError", | ||
"RetryInitializer", | ||
"if_idr_exception", | ||
"if_exception_type_factory", | ||
] |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Final | ||
|
||
from .types import RetryConfig | ||
|
||
RETRY_CONFIG_KEY: Final[str] = "RETRY" | ||
|
||
DEFAULT_DEADLINE: Final[float] = 60.0 * 5 # In seconds | ||
|
||
DEFAULT_INITIAL_DELAY: Final[float] = 1.0 # In seconds | ||
|
||
DEFAULT_MAXIMUM_DELAY: Final[float] = 60.0 # In seconds | ||
|
||
DEFAULT_MULTIPLICATIVE_FACTOR: Final[float] = 2.0 | ||
|
||
DEFAULT_RETRY_CONFIG: Final[RetryConfig] = { | ||
"default_deadline": DEFAULT_DEADLINE, | ||
"default_initial_delay": DEFAULT_INITIAL_DELAY, | ||
"default_maximum_delay": DEFAULT_MAXIMUM_DELAY, | ||
"default_multiplicative_factor": DEFAULT_MULTIPLICATIVE_FACTOR, | ||
"enable_retries": True, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from app.core import IDRClientException | ||
|
||
|
||
class RetryError(IDRClientException): | ||
"""An exception used to indicate that a retry failed.""" | ||
|
||
def __init__(self, exp: BaseException, message="Deadline exceeded."): | ||
self._exp: BaseException = exp | ||
super().__init__(message, self._exp) |
Oops, something went wrong.