-
Notifications
You must be signed in to change notification settings - Fork 149
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
Minimum delay #92
Comments
I was looking for how to change the initial delay, and it took a bit to figure out that
import backoff
def backoff_handler(details):
print(
"Backing off {wait:0.1f} seconds after {tries} tries "
"calling function {target} with args {args} and kwargs "
"{kwargs}".format(**details)
)
@backoff.on_exception(
backoff.expo,
Exception,
max_tries=5,
on_backoff=backoff_handler,
jitter=None,
factor=2,
)
def myfunc():
print("called myfunc")
raise Exception("myfunc failed")
if __name__ == "__main__":
myfunc()
|
For anyone coming to this issue as I did, this is the approach I took for this: def _min_expo_wait(min_wait: float):
"""Exponential backoff with a minimum wait time."""
def f(*args, **kwargs):
yield max(min_wait, next(backoff.expo(*args, **kwargs), min_wait))
return f
@backoff.on_exception(
_min_expo_wait(60.0),
some.Exception,
max_tries=3,
) The original proposed formula do not match with my expectation of exponential wait with a minimum, the code below will follow this one instead:
|
Here is my version for alexapy:
The
and for
Thank you @sryabkov and @photonbit! Ref: |
Is there a way to specify a minimum delay? For example, we want the first retry to be at 15 seconds and then increase the delay per the formula?
If not, any issue if we add one? I can submit a PR.
The text was updated successfully, but these errors were encountered: