-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add 'on_error' argument to 'retry.retry_target' and 'Retry'. #3891
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 'on_error' argument to 'retry.retry_target' and 'Retry'. #3891
Conversation
Permit application code to reset / fix-up state before retrying. See: #3889
dhermes
left a comment
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.
LGTM though I think you should let @jonparrott have a look before merging
core/google/api/core/retry.py
Outdated
| sleep_generator (Iterator[float]): An infinite iterator that determines | ||
| how long to sleep between retries. | ||
| deadline (float): How long to keep retrying the target. | ||
| on_error(Callable): A function to call while processing a retryable |
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
| Args: | ||
| func (Callable): The callable to add retry behavior to. | ||
| on_error(Callable): A function to call while processing a |
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.
| raise ValueError() | ||
| return 42 | ||
|
|
||
| result = retry.retry_target( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| result = retry.retry_target( | ||
| target, predicate, range(10), None, on_error=on_error) | ||
|
|
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.
theacodes
left a comment
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.
looks mostly good, just a few questions.
core/google/api/core/retry.py
Outdated
| raise | ||
| last_exc = exc | ||
| if on_error is not None: | ||
| on_error() |
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
| sleep_generator (Iterator[float]): An infinite iterator that determines | ||
| how long to sleep between retries. | ||
| deadline (float): How long to keep retrying the target. | ||
| on_error(Callable): A function to call while processing a retryable |
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.
| self._deadline = deadline | ||
|
|
||
| def __call__(self, func): | ||
| def __call__(self, func, on_error=None): |
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.
Permit application code to reset / fix-up state before retrying.
Permit application code to reset / fix-up state before retrying.
See: #3889