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

Feature Request - ability to ignore failures from long ago for long running function #37

Open
mdavis-xyz opened this issue Sep 14, 2020 · 1 comment

Comments

@mdavis-xyz
Copy link

Use Case

I have a function which will set up a websocket connection to a server. This connection should run forever.

Sometimes websockets break, and a simple retry will get them up again.
So I want a retry decorator.

But if it doesn't come up again, and each attempt to reconnect immediately fails, I want to eventually give up, and fail the overall script.

Lets say I set tries=5.
At 10am the websocket went down, and after 4 failed attempts to retry, it succeeded on the 5th (final) retry.
Now the websocket is fine and runs until 5pm, when it disconnects.
This was all one function call, inside the function, inside the decorator for many hours.
At 5pm, I want the decorator to retry. But the total retry count is already at 4 (from 10am), so it won't retry at 5pm.
I want to tell the decorator to reset the tries count if it hasn't seen an exception after a certain time period.

Solution

Add an extra argument to the decorator, ignore_older_than, which is a number of seconds.
e.g. in the case above, maybe set ignore_older_than=60*5 to reset the count for any errors older than 5 minutes.

The way this would interact with backoff is that the sleep between attempts equals delay * (backoff^n) where n is the number of exceptions caught in the last ignore_older_than seconds.

PR

I'm happy to write this PR myself. I just want to check that this is something you would accept.

@hudcap
Copy link

hudcap commented Sep 15, 2022

I came here for exactly this, but it looks like this package is no longer being maintained...

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

No branches or pull requests

2 participants