dis_spawner/
state.rs

1use std::fmt::{Display, Debug};
2
3
4#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
5pub enum SessionLivedBackendState {
6    /// The `SessionLivedBackend` object exists.
7    Submitted,
8
9    /// The pod and service backing a `SessionLivedBackend` exist.
10    Constructed,
11
12    /// The pod that backs a `SessionLivedBackend` has been assigned to a node.
13    Scheduled,
14
15    /// The pod that backs a `SessionLivedBackend` is running.
16    Running,
17
18    /// The pod that backs a `SessionLivedBackend` is accepting new connections.
19    Ready,
20
21    /// The `SessionLivedBackend` has been marked as swept, meaning that it can be deleted.
22    Swept,
23
24    /// The backend failed.
25    Failed,
26}
27
28impl Default for SessionLivedBackendState {
29    fn default() -> Self {
30        SessionLivedBackendState::Submitted
31    }
32}
33
34impl Display for SessionLivedBackendState {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        Debug::fmt(&self, f)
37    }
38}
39
40impl SessionLivedBackendState {
41    pub fn message(&self) -> String {
42        match self {
43            SessionLivedBackendState::Submitted => {
44                "SessionLivedBackend object created.".to_string()
45            }
46            SessionLivedBackendState::Constructed => {
47                "Backing resources created by Spawner.".to_string()
48            }
49            SessionLivedBackendState::Scheduled => {
50                "Backing pod was scheduled by Kubernetes.".to_string()
51            }
52            SessionLivedBackendState::Running => "Pod was observed running.".to_string(),
53            SessionLivedBackendState::Ready => {
54                "Pod was observed listening on TCP port.".to_string()
55            }
56            SessionLivedBackendState::Swept => {
57                "SessionLivedBackend was found idle and swept.".to_string()
58            }
59            &SessionLivedBackendState::Failed => {
60                "SessionLivedBackend failed.".to_string()
61            }
62        }
63    }
64}