Skip to content

Commit

Permalink
feat: support to parse duration by humantime-serde (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Jan 3, 2024
1 parent d527287 commit 594e721
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dragonfly-client"
version = "0.1.6"
version = "0.1.7"
authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git"
Expand Down Expand Up @@ -75,3 +75,4 @@ hashring = "0.3.3"
libc = "0.2"
fslock = "0.2.1"
openssl = { version = "0.10", features = ["vendored"] }
humantime-serde = "1.1.1"
30 changes: 23 additions & 7 deletions src/config/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub struct Download {
pub server: DownloadServer,

// piece_timeout is the timeout for downloading a piece from source.
#[serde(default = "default_download_piece_timeout")]
#[serde(default = "default_download_piece_timeout", with = "humantime_serde")]
pub piece_timeout: Duration,

// concurrent_piece_count is the number of concurrent pieces to download.
Expand Down Expand Up @@ -301,12 +301,18 @@ pub struct Scheduler {
// announce_interval is the interval to announce peer to the scheduler.
// Announcer will provide the scheduler with peer information for scheduling,
// peer information includes cpu, memory, etc.
#[serde(default = "default_scheduler_announce_interval")]
#[serde(
default = "default_scheduler_announce_interval",
with = "humantime_serde"
)]
pub announce_interval: Duration,

// schedule_timeout is the timeout for scheduling. If the scheduling timesout, dfdaemon will back-to-source
// download if enable_back_to_source is true, otherwise dfdaemon will return download failed.
#[serde(default = "default_scheduler_schedule_timeout")]
#[serde(
default = "default_scheduler_schedule_timeout",
with = "humantime_serde"
)]
pub schedule_timeout: Duration,

// max_schedule_count is the max count of schedule.
Expand Down Expand Up @@ -381,7 +387,10 @@ pub struct SeedPeer {
pub cluster_id: u64,

// keepalive_interval is the interval to keep alive with manager.
#[serde(default = "default_seed_peer_keepalive_interval")]
#[serde(
default = "default_seed_peer_keepalive_interval",
with = "humantime_serde"
)]
pub keepalive_interval: Duration,
}

Expand All @@ -402,7 +411,10 @@ impl Default for SeedPeer {
#[serde(default, rename_all = "camelCase")]
pub struct Dynconfig {
// refresh_interval is the interval to refresh dynamic configuration from manager.
#[serde(default = "default_dynconfig_refresh_interval")]
#[serde(
default = "default_dynconfig_refresh_interval",
with = "humantime_serde"
)]
pub refresh_interval: Duration,
}

Expand Down Expand Up @@ -438,7 +450,11 @@ impl Default for Storage {
#[serde(default, rename_all = "camelCase")]
pub struct Policy {
// task_ttl is the ttl of the task.
#[serde(default = "default_gc_policy_task_ttl", rename = "taskTTL")]
#[serde(
default = "default_gc_policy_task_ttl",
rename = "taskTTL",
with = "humantime_serde"
)]
pub task_ttl: Duration,

// dist_high_threshold_percent is the high threshold percent of the disk usage.
Expand Down Expand Up @@ -470,7 +486,7 @@ impl Default for Policy {
#[serde(default, rename_all = "camelCase")]
pub struct GC {
// interval is the interval to do gc.
#[serde(default = "default_gc_interval")]
#[serde(default = "default_gc_interval", with = "humantime_serde")]
pub interval: Duration,

// policy is the gc policy.
Expand Down

0 comments on commit 594e721

Please sign in to comment.