Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 3 commits into from
Aug 29, 2017
Merged

Add 'on_error' argument to 'retry.retry_target' and 'Retry'. #3891

merged 3 commits into from
Aug 29, 2017

Conversation

tseaver
Copy link
Contributor

@tseaver tseaver commented Aug 28, 2017

Permit application code to reset / fix-up state before retrying.

See: #3889

Permit application code to reset / fix-up state before retrying.

See:
#3889
@tseaver tseaver requested a review from theacodes August 28, 2017 20:49
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 28, 2017
Copy link
Contributor

@dhermes dhermes left a 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

@@ -150,6 +150,9 @@ def retry_target(target, predicate, sleep_generator, deadline):
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.

"""Wrap a callable with retry behavior.

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.


assert result == 42
assert call_count['target'] == 3
assert call_count['on_error'] == 2

This comment was marked as spam.

assert call_count['target'] == 3
assert call_count['on_error'] == 2

sleep.assert_has_calls([mock.call(0), mock.call(1)])

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@theacodes theacodes left a 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.

@@ -177,6 +180,8 @@ def retry_target(target, predicate, sleep_generator, deadline):
if not predicate(exc):
raise
last_exc = exc
if on_error is not None:
on_error()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -150,6 +150,9 @@ def retry_target(target, predicate, sleep_generator, deadline):
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.

@@ -226,11 +231,14 @@ def __init__(
self._maximum = maximum
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.

This comment was marked as spam.

@theacodes
Copy link
Contributor

This is fine to merge once on_error is passed the exc. Then, @tseaver can use it to make #3889 much simpler.

@tseaver tseaver merged commit 9c4144b into googleapis:master Aug 29, 2017
@tseaver tseaver deleted the core-retry_target-add-on_error-argument branch August 29, 2017 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: core cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.