You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 equalsdelay
* (backoff
^n
) wheren
is the number of exceptions caught in the lastignore_older_than
seconds.PR
I'm happy to write this PR myself. I just want to check that this is something you would accept.
The text was updated successfully, but these errors were encountered: