1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::fmt::{Display, Debug};


#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub enum SessionLivedBackendState {
    /// The `SessionLivedBackend` object exists.
    Submitted,

    /// The pod and service backing a `SessionLivedBackend` exist.
    Constructed,

    /// The pod that backs a `SessionLivedBackend` has been assigned to a node.
    Scheduled,

    /// The pod that backs a `SessionLivedBackend` is running.
    Running,

    /// The pod that backs a `SessionLivedBackend` is accepting new connections.
    Ready,

    /// The `SessionLivedBackend` has been marked as swept, meaning that it can be deleted.
    Swept,
}

impl Default for SessionLivedBackendState {
    fn default() -> Self {
        SessionLivedBackendState::Submitted
    }
}

impl Display for SessionLivedBackendState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(&self, f)
    }
}

impl SessionLivedBackendState {
    pub fn message(&self) -> String {
        match self {
            SessionLivedBackendState::Submitted => {
                "SessionLivedBackend object created.".to_string()
            }
            SessionLivedBackendState::Constructed => {
                "Backing resources created by Spawner.".to_string()
            }
            SessionLivedBackendState::Scheduled => {
                "Backing pod was scheduled by Kubernetes.".to_string()
            }
            SessionLivedBackendState::Running => "Pod was observed running.".to_string(),
            SessionLivedBackendState::Ready => {
                "Pod was observed listening on TCP port.".to_string()
            }
            SessionLivedBackendState::Swept => {
                "SessionLivedBackend was found idle and swept.".to_string()
            }
        }
    }
}