-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add google.api.core.retry.Retry decorator #3835
Add google.api.core.retry.Retry decorator #3835
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM (thanks for keeping this PR small)
core/google/api/core/retry.py
Outdated
"""Helpers for retrying functions with exponential back-off.""" | ||
"""Helpers for retrying functions with exponential back-off. | ||
|
||
The :cls`Retry` decorator can be used to retry function that raise exceptions |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
predicate (Callable[Exception]): A callable that should return ``True`` | ||
if the given exception is retryable. | ||
initial (float): The minimum about of time to delay. This must | ||
be greater than 0. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
predicate=if_transient_error, | ||
initial=1, | ||
maximum=60, | ||
multiplier=2, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
maximum (float): The maximum about of time to delay. | ||
multiplier (float): The multiplier applied to the delay. | ||
jitter (float): The maximum about of randomness to apply to the delay. | ||
deadline (float): How long to keep retrying. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
be greater than 0. | ||
maximum (float): The maximum about of time to delay. | ||
multiplier (float): The multiplier applied to the delay. | ||
jitter (float): The maximum about of randomness to apply to the delay. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
""" | ||
return Retry( | ||
predicate=self._predicate, | ||
initial=initial if initial is not None else self._initial, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
'<Retry predicate={}, initial={:.1f}, maximum={:.1f}, ' | ||
'multiplier={:.1f}, jitter={:.1f}, deadline={:.1f}>'.format( | ||
self._predicate, self._initial, self._maximum, | ||
self._multiplier, self._jitter, self._deadline)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM |
core/google/api/core/retry.py
Outdated
"""Helpers for retrying functions with exponential back-off.""" | ||
"""Helpers for retrying functions with exponential back-off. | ||
|
||
The :cls`Retry` decorator can be used to retry functions that raise exceptions |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
@@ -77,7 +125,8 @@ def exponential_sleep_generator( | |||
be greater than 0. | |||
maximum (float): The maximum about of time to delay. | |||
multiplier (float): The multiplier applied to the delay. | |||
jitter (float): The maximum about of randomness to apply to the delay. | |||
max_jitter (float): The maximum about of randomness to apply to the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/retry.py
Outdated
return retry_wrapped_func | ||
|
||
def with_deadline(self, deadline): | ||
"""Returns a copy of this retry with the given deadline. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine. Only putting "comment" since in Hangouts, @jonparrott suggested he does plan on changing the jitter algorithm.
If you end up deciding to leave it, then LGTM. If you end up deciding to change, it I will re-review once you have.
* Add google.api.core.retry.Retry decorator * Add futures dependency * Change jitter algorithm
* Add google.api.core.retry.Retry decorator * Add futures dependency * Change jitter algorithm
* Add google.api.core.retry.Retry decorator * Add futures dependency * Change jitter algorithm
No description provided.