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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum BuildState {
Queued,
Leased,
Running,
BlockedMissingDep,
Succeeded,
Failed,
Cancelled,
}
impl BuildState {
pub const ALL: &'static [BuildState] = &[
BuildState::Queued,
BuildState::Leased,
BuildState::Running,
BuildState::BlockedMissingDep,
BuildState::Succeeded,
BuildState::Failed,
BuildState::Cancelled,
];
pub fn as_str(&self) -> &'static str {
match self {
BuildState::Queued => "queued",
BuildState::Leased => "leased",
BuildState::Running => "running",
BuildState::BlockedMissingDep => "blocked_missing_dep",
BuildState::Succeeded => "succeeded",
BuildState::Failed => "failed",
BuildState::Cancelled => "cancelled",
}
}
pub fn parse(s: &str) -> Option<BuildState> {
BuildState::ALL.iter().copied().find(|b| b.as_str() == s)
}
pub fn is_terminal(&self) -> bool {
matches!(
self,
BuildState::Succeeded | BuildState::Failed | BuildState::Cancelled
)
}
pub fn can_transition(&self, to: BuildState) -> bool {
use BuildState::*;
if *self == to {
return true;
}
match self {
Queued => matches!(to, Leased | Running | BlockedMissingDep | Cancelled),
Leased => matches!(to, Running | Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
Running => matches!(to, Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
BlockedMissingDep => matches!(to, Queued | Cancelled),
Failed => matches!(to, Queued | Running),
Cancelled => to == Queued,
Succeeded => false,
}
}
pub fn predecessors(to: BuildState) -> Vec<&'static str> {
BuildState::ALL
.iter()
.filter(|from| from.can_transition(to))
.map(|from| from.as_str())
.collect()
}
pub fn active() -> &'static [BuildState] {
&[
BuildState::Queued,
BuildState::Running,
BuildState::Leased,
BuildState::BlockedMissingDep,
]
}
}
impl std::fmt::Display for BuildState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StepState {
Pending,
Running,
Succeeded,
Failed,
Interrupted,
Skipped,
}
impl StepState {
pub const ALL: &'static [StepState] = &[
StepState::Pending,
StepState::Running,
StepState::Succeeded,
StepState::Failed,
StepState::Interrupted,
StepState::Skipped,
];
pub fn as_str(&self) -> &'static str {
match self {
StepState::Pending => "pending",
StepState::Running => "running",
StepState::Succeeded => "succeeded",
StepState::Failed => "failed",
StepState::Interrupted => "interrupted",
StepState::Skipped => "skipped",
}
}
pub fn parse(text: &str) -> Option<StepState> {
StepState::ALL.iter().copied().find(|st| st.as_str() == text)
}
pub fn is_done(&self) -> bool {
matches!(self, StepState::Succeeded | StepState::Skipped)
}
pub fn can_transition(&self, to: StepState) -> bool {
use StepState::*;
if *self == to {
return true;
}
match self {
Pending => matches!(to, Running | Succeeded | Failed | Interrupted | Skipped),
Running => matches!(to, Pending | Succeeded | Failed | Interrupted | Skipped),
Failed | Interrupted => matches!(to, Pending | Running),
Succeeded | Skipped => false,
}
}
pub fn predecessors(to: StepState) -> Vec<&'static str> {
StepState::ALL
.iter()
.filter(|from| from.can_transition(to))
.map(|from| from.as_str())
.collect()
}
}
impl std::fmt::Display for StepState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
pub const BUILD_STEPS: &[&str] = &[
"materialize",
"plan",
"chroot",
"sources",
"pkgver",
"build",
"collect",
"verify",
"ingest",
"publish",
];
|