From 594e721eb0a58e78e4a89568f12c892b953eaf56 Mon Sep 17 00:00:00 2001 From: Gaius Date: Wed, 3 Jan 2024 15:49:32 +0800 Subject: [PATCH] feat: support to parse duration by humantime-serde (#192) Signed-off-by: Gaius --- Cargo.toml | 3 ++- src/config/dfdaemon.rs | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9916a15a..9b2632d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" diff --git a/src/config/dfdaemon.rs b/src/config/dfdaemon.rs index dcdd9f29..cd178c08 100644 --- a/src/config/dfdaemon.rs +++ b/src/config/dfdaemon.rs @@ -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. @@ -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. @@ -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, } @@ -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, } @@ -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. @@ -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.