-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Unlimited retries possible in implementation, but not trough public API #48
Comments
Yes, we have not presented a direct method for that. Might you have a requirement for this? We can use with_max_times to workaround it: let builder = ConstantBuilder::default().with_max_times(usize::MAX); |
thats what i'm using right now, but feels a bit hacky, Maybe a new function like |
Seems not a good idea to me. I plan to add a let f = FnBuilder::new(|| Some(Durtion::from_secs(1))); What do you think? |
It should follow the principle of least surprise. User of library shouldn't look into the implementation to find out what function will do. I've spent some time finding out why it nearly instantly exits with such setup:
|
Sorry for that. I will alter the |
Oh, sorry, seems like we have misunderstanding. Jitter is not an issue, it's working as it's said in docs. But the need to write For example, Maybe it's possible to have different build methods? impl FibonacciBackoff {
/// Create a new FibonacciBuilder with all fields set to None
pub fn builder() -> FibonacciBuilder {
FibonacciBuilder {
jitter: None,
min_delay: None,
max_delay: None,
max_times: None,
}
}
}
#[derive(Debug, Clone)]
pub struct FibonacciBuilder {
jitter: Option<bool>,
min_delay: Option<Duration>,
max_delay: Option<Duration>,
max_times: Option<usize>,
}
impl FibonacciBuilder {
// ... existing methods ...
/// Build a FibonacciBackoff with the specified maximum number of retries
pub fn build_with_max_retries(self, max_retries: usize) -> FibonacciBackoff {
FibonacciBackoff {
jitter: self.jitter.unwrap_or(false),
min_delay: self.min_delay.unwrap_or_else(|| Duration::from_secs(1)),
max_delay: self.max_delay,
max_times: Some(max_retries),
previous_delay: None,
current_delay: None,
attempts: 0,
}
}
/// Build a FibonacciBackoff with no maximum number of retries
pub fn build_endless(self) -> FibonacciBackoff {
FibonacciBackoff {
jitter: self.jitter.unwrap_or(false),
min_delay: self.min_delay.unwrap_or_else(|| Duration::from_secs(1)),
max_delay: self.max_delay,
max_times: None,
previous_delay: None,
current_delay: None,
attempts: 0,
}
}
}
impl BackoffBuilder for FibonacciBuilder {
type Backoff = FibonacciBackoff;
fn build(&self) -> Self::Backoff {
FibonacciBackoff {
jitter: self.jitter.unwrap_or(false),
min_delay: self.min_delay.unwrap_or_else(|| Duration::from_secs(1)),
max_delay: self.max_delay,
max_times: self.max_times,
previous_delay: None,
current_delay: None,
attempts: 0,
}
}
} With such api, it's impossible to miss, that it will retry 3 times and exit after that:) |
Thanks for the reply.
It's intentional that FibonacciBackoff has the value I chose based on my own experience as a good default. I personally feel that setting I will take this suggestion into account while preparing the |
No actions to take so far. |
If I'm seeing this correctly, it should be possible to have unlimited retries in the implementation, but there seems no way of doing that via the public API, because the Default implementation defaults to 3 retries?
Is that intended or did I miss anything?
The text was updated successfully, but these errors were encountered: