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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActivityState {
#[serde(rename = "state")]
pub state: StatePair,
#[serde(rename = "reason", skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
#[serde(rename = "errorMessage", skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
}
impl ActivityState {
pub fn alive(&self) -> bool {
self.state.alive()
}
}
impl From<&StatePair> for ActivityState {
fn from(pending: &StatePair) -> Self {
ActivityState {
state: pending.clone(),
reason: None,
error_message: None,
}
}
}
impl From<StatePair> for ActivityState {
fn from(pending: StatePair) -> Self {
ActivityState {
state: pending,
reason: None,
error_message: None,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct StatePair(pub State, pub Option<State>);
impl StatePair {
pub fn alive(&self) -> bool {
match (&self.0, &self.1) {
(State::Terminated, _) => false,
(_, Some(State::Terminated)) => false,
_ => true,
}
}
pub fn to_pending(&self, state: State) -> Self {
StatePair(self.0.clone(), Some(state))
}
}
impl From<State> for StatePair {
fn from(state: State) -> Self {
StatePair(state, None)
}
}
impl Default for StatePair {
fn default() -> Self {
StatePair(State::default(), None)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum State {
New,
Initialized,
Deployed,
Ready,
Terminated,
Unresponsive,
}
impl Default for State {
fn default() -> Self {
State::New
}
}