-
Notifications
You must be signed in to change notification settings - Fork 266
feat(lazer): add resilient client in rust #2859
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
Changes from all commits
0849884
0f612e7
49ed653
8f6845d
dd275dc
5679ae1
67022b6
efb3f8b
cb3803e
d80ffc6
856a925
008f025
0931845
1323684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::time::Duration; | ||
|
||
use backoff::{ | ||
default::{INITIAL_INTERVAL_MILLIS, MAX_INTERVAL_MILLIS, MULTIPLIER, RANDOMIZATION_FACTOR}, | ||
ExponentialBackoff, ExponentialBackoffBuilder, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct PythLazerExponentialBackoffBuilder { | ||
initial_interval: Duration, | ||
randomization_factor: f64, | ||
multiplier: f64, | ||
max_interval: Duration, | ||
} | ||
|
||
impl Default for PythLazerExponentialBackoffBuilder { | ||
fn default() -> Self { | ||
Self { | ||
initial_interval: Duration::from_millis(INITIAL_INTERVAL_MILLIS), | ||
randomization_factor: RANDOMIZATION_FACTOR, | ||
multiplier: MULTIPLIER, | ||
max_interval: Duration::from_millis(MAX_INTERVAL_MILLIS), | ||
} | ||
} | ||
} | ||
|
||
impl PythLazerExponentialBackoffBuilder { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
|
||
/// The initial retry interval. | ||
pub fn with_initial_interval(&mut self, initial_interval: Duration) -> &mut Self { | ||
self.initial_interval = initial_interval; | ||
self | ||
} | ||
|
||
/// The randomization factor to use for creating a range around the retry interval. | ||
/// | ||
/// A randomization factor of 0.5 results in a random period ranging between 50% below and 50% | ||
/// above the retry interval. | ||
pub fn with_randomization_factor(&mut self, randomization_factor: f64) -> &mut Self { | ||
self.randomization_factor = randomization_factor; | ||
self | ||
} | ||
|
||
/// The value to multiply the current interval with for each retry attempt. | ||
pub fn with_multiplier(&mut self, multiplier: f64) -> &mut Self { | ||
self.multiplier = multiplier; | ||
self | ||
} | ||
|
||
/// The maximum value of the back off period. Once the retry interval reaches this | ||
/// value it stops increasing. | ||
pub fn with_max_interval(&mut self, max_interval: Duration) -> &mut Self { | ||
self.max_interval = max_interval; | ||
self | ||
} | ||
|
||
pub fn build(&self) -> ExponentialBackoff { | ||
ExponentialBackoffBuilder::default() | ||
.with_initial_interval(self.initial_interval) | ||
.with_randomization_factor(self.randomization_factor) | ||
.with_multiplier(self.multiplier) | ||
.with_max_interval(self.max_interval) | ||
.with_max_elapsed_time(None) | ||
.build() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm fine with this but generally my take was reexposing what we use in the API and we still use ExponentialBackoff from the backoff crate. now that you have a builder it makes sense that you have your own wrapper type for the api of the lazer client. later when you convert it you can remove the following error as well: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it's a good improvement. I'll add this + docs in another PR to unblock the progress of monitor for now. |
||
} |
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.
document here as well? maybe default as well?
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.
The reason I didn't implement default is that we need to have access token. Default doesn't make sense since it will be in an invalid state.