Skip to content

Commit

Permalink
Migrate to humantime (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz authored Dec 21, 2023
1 parent 8145172 commit 88dd311
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ clap = { version = "4", features = ["derive", "env"] }
ethereum-types = "0.14"
futures = "0.3"
hex = "0.4"
humantime = "2.1.0"
humantime-serde = "1.1.1"
hyper = "0.14"
itertools = "0.11"
num = "0.4"
Expand Down
20 changes: 10 additions & 10 deletions src/infra/config/dex/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ struct Config {
back_off_growth_factor: f64,

/// Minimum back-off time in seconds for rate limiting.
#[serde(default = "default_min_back_off")]
min_back_off: u64,
#[serde(with = "humantime_serde", default = "default_min_back_off")]
min_back_off: Duration,

/// Maximum back-off time in seconds for rate limiting.
#[serde(default = "default_max_back_off")]
max_back_off: u64,
#[serde(with = "humantime_serde", default = "default_max_back_off")]
max_back_off: Duration,

/// Settings specific to the wrapped dex API.
dex: toml::Value,
Expand All @@ -81,12 +81,12 @@ fn default_back_off_growth_factor() -> f64 {
2.0
}

fn default_min_back_off() -> u64 {
1
fn default_min_back_off() -> Duration {
Duration::from_secs(1)
}

fn default_max_back_off() -> u64 {
8
fn default_max_back_off() -> Duration {
Duration::from_secs(8)
}

/// Loads the base solver configuration from a TOML file.
Expand Down Expand Up @@ -144,8 +144,8 @@ pub async fn load<T: DeserializeOwned>(path: &Path) -> (super::Config, T) {
},
rate_limiting_strategy: RateLimitingStrategy::try_new(
config.back_off_growth_factor,
Duration::from_secs(config.min_back_off),
Duration::from_secs(config.max_back_off),
config.min_back_off,
config.max_back_off,
)
.unwrap(),
};
Expand Down

0 comments on commit 88dd311

Please sign in to comment.