Skip to content
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 a more generic handle_failure option to subsume logger #18

Open
asqui opened this issue Sep 20, 2017 · 2 comments · May be fixed by #49
Open

Add a more generic handle_failure option to subsume logger #18

asqui opened this issue Sep 20, 2017 · 2 comments · May be fixed by #49

Comments

@asqui
Copy link

asqui commented Sep 20, 2017

Logging at WARN level isn't ideal, even if you can supply your own logger you still can't (easily) change the log level that messages go to.

A more generic way to implement this would be to pass in not a logger, but a log function that gets called with information about the failure, this gives you more flexibility in how you format your log message, what level you log it at, in fact, it also gives you the flexibility to do anything else following a failure. (e.g. re-establish a connection before the next retry attempt)

Add a handle_failure argument which takes an optional function that gets called following a failure.

Open question as to whether it should be called before the sleep (better suited to logging) or after the sleep (better suited to recycling resources closer to when they will be used e.g. re-opening an FTP connection before a long sleep only to have it timeout from inactivity during the sleep won't work well.)

Maybe need both after_failure and before_retry to cover all the bases?

after_failure could potentially return a value indicating whether to retry or not, or perhaps even a value that indicates how long to wait before the retry.

Thoughts?

@jaraco
Copy link

jaraco commented Dec 13, 2017

I'd very much like to see this feature implemented, and I'd like to share some inspiration.

In jaraco.functools, I implement retry_call without implicit sleep or logging behavior, but instead using a generic cleanup parameter, which can be set to sleep (functools.partial(time.sleep, 1)) or log or both or something else.

@eevleevs
Copy link

I would also use a handler for doing something when giving up if max retries is reached.

warownia1 added a commit to warownia1/retry that referenced this issue Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants