summaryrefslogtreecommitdiffstats
path: root/src/db/model/build_state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/model/build_state.rs')
-rw-r--r--src/db/model/build_state.rs57
1 files changed, 13 insertions, 44 deletions
diff --git a/src/db/model/build_state.rs b/src/db/model/build_state.rs
index 37eee79..478f93a 100644
--- a/src/db/model/build_state.rs
+++ b/src/db/model/build_state.rs
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum BuildState {
Queued,
@@ -42,17 +41,14 @@ impl BuildState {
}
pub fn is_terminal(&self) -> bool {
- matches!(
- self,
- BuildState::Succeeded | BuildState::Failed | BuildState::Cancelled
- )
+ matches!(self, BuildState::Succeeded | BuildState::Failed | BuildState::Cancelled)
}
/// The transition table itself. `predecessors` is how production
/// enforces it; nothing outside this module asks the question directly.
- fn can_transition(&self, to: BuildState) -> bool {
- use BuildState::*;
- if *self == to {
+ fn can_transition(self, to: BuildState) -> bool {
+ use BuildState::{BlockedMissingDep, Cancelled, Failed, Leased, Queued, Running, Succeeded};
+ if self == to {
return true;
}
match self {
@@ -67,20 +63,11 @@ impl BuildState {
}
pub(crate) fn predecessors(to: BuildState) -> Vec<&'static str> {
- BuildState::ALL
- .iter()
- .filter(|from| from.can_transition(to))
- .map(|from| from.as_str())
- .collect()
+ BuildState::ALL.iter().filter(|from| from.can_transition(to)).map(BuildState::as_str).collect()
}
pub fn active() -> &'static [BuildState] {
- &[
- BuildState::Queued,
- BuildState::Running,
- BuildState::Leased,
- BuildState::BlockedMissingDep,
- ]
+ &[BuildState::Queued, BuildState::Running, BuildState::Leased, BuildState::BlockedMissingDep]
}
}
@@ -130,9 +117,9 @@ impl StepState {
matches!(self, StepState::Succeeded | StepState::Skipped)
}
- fn can_transition(&self, to: StepState) -> bool {
- use StepState::*;
- if *self == to {
+ fn can_transition(self, to: StepState) -> bool {
+ use StepState::{Failed, Interrupted, Pending, Running, Skipped, Succeeded};
+ if self == to {
return true;
}
match self {
@@ -144,11 +131,7 @@ impl StepState {
}
pub(crate) fn predecessors(to: StepState) -> Vec<&'static str> {
- StepState::ALL
- .iter()
- .filter(|from| from.can_transition(to))
- .map(|from| from.as_str())
- .collect()
+ StepState::ALL.iter().filter(|from| from.can_transition(to)).map(StepState::as_str).collect()
}
}
@@ -158,18 +141,8 @@ impl std::fmt::Display for StepState {
}
}
-pub const BUILD_STEPS: &[&str] = &[
- "materialize",
- "plan",
- "chroot",
- "sources",
- "pkgver",
- "build",
- "collect",
- "verify",
- "ingest",
- "publish",
-];
+pub const BUILD_STEPS: &[&str] =
+ &["materialize", "plan", "chroot", "sources", "pkgver", "build", "collect", "verify", "ingest", "publish"];
#[cfg(test)]
mod tests {
@@ -192,11 +165,7 @@ mod tests {
#[test]
fn the_transition_table_is_the_machine_the_code_actually_uses() {
let reachable = |from: BuildState| -> Vec<&'static str> {
- BuildState::ALL
- .iter()
- .filter(|to| from.can_transition(**to))
- .map(|to| to.as_str())
- .collect()
+ BuildState::ALL.iter().filter(|to| from.can_transition(**to)).map(super::BuildState::as_str).collect()
};
assert_eq!(reachable(BuildState::Queued), ["queued", "leased", "running", "blocked_missing_dep", "cancelled"]);
assert_eq!(