-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Allow total duration with max retries #15
feat: Allow total duration with max retries #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there's a more general-purpose API design here.
I'm thinking about:
- What if we want to set these independently?
- What if we want to calculate duration from max retries? Is that a sensible option?
For 1, what do you think about an API like:
let exponential_backoff_timed = ExponentialBackoff::builder()
.retry_bounds(Duration::from_secs(1), Duration::from_secs(6 * 60 * 60))
.max_retries(10)
.build_with_total_retry_duration(Duration::from_secs(24 * 60 * 60));
or:
ExponentialBackoff::builder()
.build_with_max_retries(5)
.with_total_retry_duration(Duration::from_secs(24 * 60 * 60));
Not sure about 2 yet, but something like this:
I might be overcomplicating it, but keen to try to find a good general-purpose API which can cover these cases, instead of committing to specific-purpose APIs.
What if we provide this API: fn build_with_total_retry_duration(
self,
total_duration: Duration,
max_retries: MaxRetries
) -> ExponentialBackoffTimed;
enum MaxRetries {
Unbounded,
Default,
Fixed(u16)
} User could:
I think that should be the default when using the |
Is this a good illustration of how it will work?
I like it. I think we might want to either find a better name for A downside is that it's a breaking change?
If you constrain both the min and max intervals, you get a fairly good idea of how long something could take... but only as long as the task is short, which is maybe a key oversight! I'm coming around to this idea. |
Yes, that's how the
Big issues with naming here...
It is, we would deprecate the current If you are onboard I'll start the implementation first thing tomorrow morning. |
…kward compat manner
….com:TrueLayer/retry-policies into maps-570-allow-max-duration-with-max-retries
6175bbd
This PR fixes one main problem, which is the fact that using a total duration we are not able to set a limit to the number of retries that will be made inside that timeframe.
We added a new
build_with_total_retry_duration_and_max_retries
method toExponentialBackoffBuilder
that calculates the number of retries that should be made if jitter1.0
was applied (which means no jitter).Since jitter can be
0..1
, the calculated number of retries is effectively the max number of retries that can be made during that duration.In
should_retry
we now check if either total duration or max attempts are exceeded.We also made the exponential's base configurable: this will allow users to exponentially delay the retries more from one another.
The default remains
2
, so this isn't a breaking change.