summaryrefslogtreecommitdiffstats
path: root/src/pipeline
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 16:49:40 +0000
committeraur-build <aur-build@localhost>2026-11-18 16:49:40 +0000
commit41fa1684de8eb13c5b76c3a3e174fece04ac5afa (patch)
tree491a2faf2dd2314f537300ccaf1e0150b54d1123 /src/pipeline
parent101f077200e80c7869e4549db645ed94b01acb1b (diff)
downloadaur-build-41fa1684de8eb13c5b76c3a3e174fece04ac5afa.tar.gz
aur-build-41fa1684de8eb13c5b76c3a3e174fece04ac5afa.zip
db: the review, step, release and subscription states are enums too
M-8 named four more machines after `build_state`, and each had the same defect in miniature: `&str` constants, a writer that took any `&str`, and a rule that lived only in the caller's discipline. They are `CandidateState`, `StepState`, `ReleaseState` and `SubscriptionState` now, all parsed through one `db::state_col` at the row boundary — a column value the code cannot name fails the read rather than becoming a state it did not ask for. The one that mattered is the review machine. `resolve_in(tx, id, &str)` would move a candidate to any state from any state, so an approval racing a rejection, or a stale worker resolving a review that had already been superseded, silently overwrote what a human had decided — the direct route to breaking I2 and I3 with no symptom anywhere. It is a compare-and-swap on `CandidateState` now: a decided review is only ever frozen, never re-decided, and a refusal names both states. `supersede_in` goes through it, so the freeze cannot resurrect a superseded review either. `StepState` gives I5 teeth. `begin_step` upserted over any existing checkpoint, including one recorded `succeeded`, so a resume that asked to re-run a finished step could rewrite the very row that told it to skip; the upsert now refuses to touch a done checkpoint and `finish_step` is a CAS. The blocked path (`running → pending`) and the reaper's `running → interrupted` are unchanged, and both are in the table. Two behaviour changes, both for the better and both tested: the UI's pause button now says "orphaned: nothing to pause" instead of rewriting an orphaned subscription back to a pausable state, and a step checkpoint that is already done makes `begin_step` an error rather than a quiet overwrite. Five tests in `tests/state_machine.rs` cover the review CAS in both directions, the frozen checkpoint, the interrupted/blocked transitions, and the unknown value in a candidate and a step row.
Diffstat (limited to 'src/pipeline')
-rw-r--r--src/pipeline/mod.rs10
-rw-r--r--src/pipeline/publish.rs4
2 files changed, 7 insertions, 7 deletions
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs
index 01c9bc5..9ddfc65 100644
--- a/src/pipeline/mod.rs
+++ b/src/pipeline/mod.rs
@@ -203,7 +203,7 @@ pub fn run_with(ctx: &Ctx) -> Result<Outcome> {
return Ok(Outcome::Cancelled);
}
let status = builds::step_status(&ctx.db, &ctx.build.id, step)?;
- if status.as_deref() == Some(step_state::SUCCEEDED) || status.as_deref() == Some(step_state::SKIPPED) {
+ if status.is_some_and(|s| s.is_done()) {
continue; // checkpoint says we already did this
}
builds::begin_step(&ctx.db, &ctx.build.id, step, ctx.attempt)?;
@@ -211,22 +211,22 @@ pub fn run_with(ctx: &Ctx) -> Result<Outcome> {
ctx.log_line(&format!("==> step {step} (attempt {})", ctx.attempt));
match steps::run_step(ctx, step) {
Ok(StepResult::Done(digest)) => {
- builds::finish_step(&ctx.db, &ctx.build.id, step, step_state::SUCCEEDED, digest.as_deref(), None)?;
+ builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Succeeded, digest.as_deref(), None)?;
builds::extend_lease(&ctx.db, &ctx.build.id, 90)?;
}
Ok(StepResult::Skipped(why)) => {
ctx.log_line(&format!(" skipped: {why}"));
- builds::finish_step(&ctx.db, &ctx.build.id, step, step_state::SKIPPED, None, None)?;
+ builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Skipped, None, None)?;
}
Ok(StepResult::Blocked(on)) => {
- builds::finish_step(&ctx.db, &ctx.build.id, step, step_state::PENDING, None, Some("blocked"))?;
+ builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Pending, None, Some("blocked"))?;
builds::block_on(&ctx.db, &ctx.build.id, &on)?;
ctx.log_line(&format!(" blocked on: {}", on.join(", ")));
return Ok(Outcome::Blocked { on });
}
Err(e) => {
let transient = e.is_transient();
- builds::finish_step(&ctx.db, &ctx.build.id, step, step_state::FAILED, None, Some(&e.to_string()))?;
+ builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Failed, None, Some(&e.to_string()))?;
builds::set_state(
&ctx.db,
&ctx.build.id,
diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs
index 877d8e1..4f21e72 100644
--- a/src/pipeline/publish.rs
+++ b/src/pipeline/publish.rs
@@ -12,7 +12,7 @@ use std::process::Command;
use std::sync::Mutex;
use crate::config::Config;
-use crate::db::{self, builds, candidate_state, candidates, Db, WorldMember};
+use crate::db::{self, builds, candidates, CandidateState, Db, WorldMember};
use crate::error::{Error, Result};
use crate::pipeline::{Collect, Ctx};
use crate::time;
@@ -247,7 +247,7 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> {
}
builds::set_release_in(tx, &build_id, release_id)?;
if let Some(cid) = candidate_id {
- candidates::resolve_in(tx, cid, candidate_state::APPROVED, &at)?;
+ candidates::resolve_in(tx, cid, CandidateState::Approved, &at)?;
}
Ok(release_id)
})