synd_runtime/daemon/
status.rs1use std::path::{Path, PathBuf};
2
3use synd_protocol::daemon::DaemonSessionStatus;
4
5use crate::placement::PlacementSpec;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum State {
9 Running,
10 NotRunning,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct Status {
15 state: State,
16 placement: PlacementSummary,
17 sessions: Option<DaemonSessionStatus>,
18}
19
20impl Status {
21 pub(crate) fn new(state: State, placement: PlacementSummary) -> Self {
22 Self {
23 state,
24 placement,
25 sessions: None,
26 }
27 }
28
29 pub(crate) fn running(placement: PlacementSummary, sessions: DaemonSessionStatus) -> Self {
30 Self {
31 state: State::Running,
32 placement,
33 sessions: Some(sessions),
34 }
35 }
36
37 pub fn state(&self) -> State {
38 self.state
39 }
40
41 pub fn placement(&self) -> &PlacementSummary {
42 &self.placement
43 }
44
45 pub fn sessions(&self) -> Option<&DaemonSessionStatus> {
46 self.sessions.as_ref()
47 }
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct PlacementSummary {
52 runtime_root: PathBuf,
53 runtime_instance_id: String,
54 database: PathBuf,
55 endpoint: PathBuf,
56 startup_lock: PathBuf,
57 daemon_claim: PathBuf,
58 daemon_claim_lock: PathBuf,
59}
60
61impl PlacementSummary {
62 pub(crate) fn from_placement(placement: &PlacementSpec) -> Self {
63 Self {
64 runtime_root: placement.root().path().to_path_buf(),
65 runtime_instance_id: placement.instance().id().to_string(),
66 database: placement.instance().canonical_database_path().to_path_buf(),
67 endpoint: placement.endpoint().path().to_path_buf(),
68 startup_lock: placement.startup_lock_path().path().to_path_buf(),
69 daemon_claim: placement.daemon_claim_path().path().to_path_buf(),
70 daemon_claim_lock: placement.daemon_claim_lock_path().path().to_path_buf(),
71 }
72 }
73
74 pub fn runtime_root(&self) -> &Path {
75 &self.runtime_root
76 }
77
78 pub fn runtime_instance_id(&self) -> &str {
79 &self.runtime_instance_id
80 }
81
82 pub fn database(&self) -> &Path {
83 &self.database
84 }
85
86 pub fn endpoint(&self) -> &Path {
87 &self.endpoint
88 }
89
90 pub fn startup_lock(&self) -> &Path {
91 &self.startup_lock
92 }
93
94 pub fn daemon_claim(&self) -> &Path {
95 &self.daemon_claim
96 }
97
98 pub fn daemon_claim_lock(&self) -> &Path {
99 &self.daemon_claim_lock
100 }
101}
102
103#[derive(Debug, Clone, PartialEq, Eq)]
104pub struct ShutdownResult {
105 status: Status,
106}
107
108impl ShutdownResult {
109 pub fn new(status: Status) -> Self {
110 Self { status }
111 }
112
113 pub fn status(&self) -> &Status {
114 &self.status
115 }
116}