Skip to main content

synd_protocol/
daemon.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5pub const STATUS_PATH: &str = "/daemon/status";
6
7/// Response body returned by the daemon status endpoint.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct DaemonStatusResponse {
10    sessions: DaemonSessionStatus,
11}
12
13impl DaemonStatusResponse {
14    pub fn new(sessions: DaemonSessionStatus) -> Self {
15        Self { sessions }
16    }
17
18    pub fn sessions(&self) -> &DaemonSessionStatus {
19        &self.sessions
20    }
21}
22
23/// Snapshot of daemon session lifecycle state.
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25pub struct DaemonSessionStatus {
26    active_sessions: usize,
27    lease_duration: Duration,
28    sweep_interval: Duration,
29    idle_shutdown: DaemonIdleShutdownStatus,
30}
31
32impl DaemonSessionStatus {
33    pub fn new(
34        active_sessions: usize,
35        lease_duration: Duration,
36        sweep_interval: Duration,
37        idle_shutdown: DaemonIdleShutdownStatus,
38    ) -> Self {
39        Self {
40            active_sessions,
41            lease_duration,
42            sweep_interval,
43            idle_shutdown,
44        }
45    }
46
47    pub fn active_sessions(&self) -> usize {
48        self.active_sessions
49    }
50
51    pub fn lease_duration(&self) -> Duration {
52        self.lease_duration
53    }
54
55    pub fn sweep_interval(&self) -> Duration {
56        self.sweep_interval
57    }
58
59    pub fn idle_shutdown(&self) -> &DaemonIdleShutdownStatus {
60        &self.idle_shutdown
61    }
62}
63
64/// Snapshot of daemon idle-shutdown state.
65#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
66pub struct DaemonIdleShutdownStatus {
67    enabled: bool,
68    grace: Option<Duration>,
69    pending: bool,
70}
71
72impl DaemonIdleShutdownStatus {
73    pub fn disabled() -> Self {
74        Self {
75            enabled: false,
76            grace: None,
77            pending: false,
78        }
79    }
80
81    pub fn enabled(grace: Duration, pending: bool) -> Self {
82        Self {
83            enabled: true,
84            grace: Some(grace),
85            pending,
86        }
87    }
88
89    pub fn is_enabled(&self) -> bool {
90        self.enabled
91    }
92
93    pub fn grace(&self) -> Option<Duration> {
94        self.grace
95    }
96
97    pub fn is_pending(&self) -> bool {
98        self.pending
99    }
100}