Skip to content

Commit 594e721

Browse files
authored
feat: support to parse duration by humantime-serde (#192)
Signed-off-by: Gaius <[email protected]>
1 parent d527287 commit 594e721

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dragonfly-client"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["The Dragonfly Developers"]
55
homepage = "https://d7y.io/"
66
repository = "https://github.com/dragonflyoss/client.git"
@@ -75,3 +75,4 @@ hashring = "0.3.3"
7575
libc = "0.2"
7676
fslock = "0.2.1"
7777
openssl = { version = "0.10", features = ["vendored"] }
78+
humantime-serde = "1.1.1"

src/config/dfdaemon.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub struct Download {
235235
pub server: DownloadServer,
236236

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

241241
// concurrent_piece_count is the number of concurrent pieces to download.
@@ -301,12 +301,18 @@ pub struct Scheduler {
301301
// announce_interval is the interval to announce peer to the scheduler.
302302
// Announcer will provide the scheduler with peer information for scheduling,
303303
// peer information includes cpu, memory, etc.
304-
#[serde(default = "default_scheduler_announce_interval")]
304+
#[serde(
305+
default = "default_scheduler_announce_interval",
306+
with = "humantime_serde"
307+
)]
305308
pub announce_interval: Duration,
306309

307310
// schedule_timeout is the timeout for scheduling. If the scheduling timesout, dfdaemon will back-to-source
308311
// download if enable_back_to_source is true, otherwise dfdaemon will return download failed.
309-
#[serde(default = "default_scheduler_schedule_timeout")]
312+
#[serde(
313+
default = "default_scheduler_schedule_timeout",
314+
with = "humantime_serde"
315+
)]
310316
pub schedule_timeout: Duration,
311317

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

383389
// keepalive_interval is the interval to keep alive with manager.
384-
#[serde(default = "default_seed_peer_keepalive_interval")]
390+
#[serde(
391+
default = "default_seed_peer_keepalive_interval",
392+
with = "humantime_serde"
393+
)]
385394
pub keepalive_interval: Duration,
386395
}
387396

@@ -402,7 +411,10 @@ impl Default for SeedPeer {
402411
#[serde(default, rename_all = "camelCase")]
403412
pub struct Dynconfig {
404413
// refresh_interval is the interval to refresh dynamic configuration from manager.
405-
#[serde(default = "default_dynconfig_refresh_interval")]
414+
#[serde(
415+
default = "default_dynconfig_refresh_interval",
416+
with = "humantime_serde"
417+
)]
406418
pub refresh_interval: Duration,
407419
}
408420

@@ -438,7 +450,11 @@ impl Default for Storage {
438450
#[serde(default, rename_all = "camelCase")]
439451
pub struct Policy {
440452
// task_ttl is the ttl of the task.
441-
#[serde(default = "default_gc_policy_task_ttl", rename = "taskTTL")]
453+
#[serde(
454+
default = "default_gc_policy_task_ttl",
455+
rename = "taskTTL",
456+
with = "humantime_serde"
457+
)]
442458
pub task_ttl: Duration,
443459

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

476492
// policy is the gc policy.

0 commit comments

Comments
 (0)