summaryrefslogtreecommitdiffstats
path: root/src/http
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 16:31:58 +0000
committeraur-build <aur-build@localhost>2026-11-18 16:31:58 +0000
commit101f077200e80c7869e4549db645ed94b01acb1b (patch)
treef8560d143ef2afe1a3d675a203c693a09cbc451b /src/http
parentf8370b48f3e4464a1454d0ff7af1819b5448c619 (diff)
downloadaur-build-101f077200e80c7869e4549db645ed94b01acb1b.tar.gz
aur-build-101f077200e80c7869e4549db645ed94b01acb1b.zip
db: the build state machine is an enum, and a state write is a compare-and-swap
`build_state` was seven `&str` constants and `set_state(&str)` would write any string a caller invented, so the machine existed only as `WHERE state IN (...)` clauses scattered across six modules and nothing could say that `succeeded → running` is nonsense. It is `db::model::BuildState` now: parsed where a row is read (a state the code cannot name is an error, not an empty string — which also retires m-12's `current_state` returning `""`), and `set_state` takes the variant and writes only if the row's current state is one of `to`'s legal predecessors. A refused transition writes nothing and says why. Writing the machine down surfaced three things that were true of the flows but of nobody's documentation. The step loop re-asserts `Running` at every step boundary, so a self-write is a no-op and not a move — every state accepts its own name. A failed build is resumed *on its own row* (I5: the step checkpoints say where to continue), so `failed → running` is a real transition. And `builds::retry` — the UI's requeue button — moved any row to `queued` unconditionally, including one that had already published, re-queueing a build whose every step was checkpointed as done; it goes through the machine now and is refused with a reason. `requeue_transient` likewise. What the CAS buys is the zombie case, which no test covered: a worker's lease expires mid-step, the reaper returns the build to the queue, and the original worker — still running — comes back and writes `succeeded` over whatever the new owner has since done. That write now fails loudly and the queue keeps ownership. `builds_for_pkgbase` had a second, hand-copied row mapper that dropped unreadable rows with `filter_map(|r| r.ok())`; it shares `row_to_build` now and a bad row fails the query instead of vanishing from the package page (m-9's policy, applied where it bit). `tests/state_machine.rs` pins the whole table, the zombie refusal, the unknown state, the terminal build that does not move, and the requeue-of-a-published- build refusal. `tests/live.rs` walks a build through `running` before succeeding instead of teleporting it.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/routes.rs12
-rw-r--r--src/http/sse.rs6
2 files changed, 7 insertions, 11 deletions
diff --git a/src/http/routes.rs b/src/http/routes.rs
index d3b184b..926d2a8 100644
--- a/src/http/routes.rs
+++ b/src/http/routes.rs
@@ -720,7 +720,7 @@ fn package_detail(state: &State, req: &Req, name: &str) -> Res {
id_short: short(&b.id),
id: b.id,
kind: b.kind,
- state: b.state,
+ state: b.state.to_string(),
step: b.current_step.unwrap_or_default(),
})
.collect();
@@ -828,7 +828,7 @@ fn build_version(db: &Db, b: &builds::BuildRow) -> String {
fn build_rows(state: &State) -> Vec<BuildRow> {
builds::list(
&state.db,
- &[build_state::QUEUED, build_state::RUNNING, build_state::LEASED, build_state::BLOCKED_MISSING_DEP],
+ BuildState::active(),
100,
)
.unwrap_or_default()
@@ -846,7 +846,7 @@ fn build_rows(state: &State) -> Vec<BuildRow> {
pkgbase,
version,
kind: b.kind,
- state: b.state,
+ state: b.state.to_string(),
step: b.current_step.unwrap_or_default(),
lease: b.lease_expires_at.unwrap_or_else(|| "—".into()),
cancel: b.cancel_requested,
@@ -870,7 +870,7 @@ fn builds_page(state: &State, req: &Req) -> Res {
}
fn recent_rows(state: &State) -> Vec<BuildRow> {
- builds::list(&state.db, &[build_state::FAILED, build_state::SUCCEEDED], 10)
+ builds::list(&state.db, &[BuildState::Failed, BuildState::Succeeded], 10)
.unwrap_or_default()
.into_iter()
.map(|b| {
@@ -882,7 +882,7 @@ fn recent_rows(state: &State) -> Vec<BuildRow> {
pkgbase,
version,
kind: b.kind,
- state: b.state,
+ state: b.state.to_string(),
step: b.current_step.unwrap_or_default(),
lease: String::new(),
cancel: b.cancel_requested,
@@ -931,7 +931,7 @@ fn build_detail(state: &State, req: &Req, id: &str) -> Res {
pkgbase,
version: build_version(db, &b),
kind: b.kind,
- state: b.state,
+ state: b.state.to_string(),
error: b.error.clone().unwrap_or_default(),
blocked_on,
steps,
diff --git a/src/http/sse.rs b/src/http/sse.rs
index e141926..5bfb75b 100644
--- a/src/http/sse.rs
+++ b/src/http/sse.rs
@@ -15,7 +15,6 @@ use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
use crate::db::builds;
-use crate::db::model::build_state;
/// How long a tail will wait for a build that never finishes. A viewer that
/// outlives this gets a clean end and can reconnect.
@@ -53,10 +52,7 @@ impl LogTail {
fn terminal(&self) -> bool {
match builds::get(&self.db, &self.build_id) {
- Ok(Some(b)) => matches!(
- b.state.as_str(),
- build_state::SUCCEEDED | build_state::FAILED | build_state::CANCELLED
- ),
+ Ok(Some(b)) => b.state.is_terminal(),
// A build row that vanished is not going to produce more output.
Ok(None) => true,
// A database hiccup should not end the stream; the next poll tries