summaryrefslogtreecommitdiffstats
path: root/src/db/queries.rs
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/db/queries.rs
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/db/queries.rs')
-rw-r--r--src/db/queries.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/db/queries.rs b/src/db/queries.rs
index b768f83..e1f25b7 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -661,16 +661,10 @@ pub fn builds_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result<Vec<cr
priority, cancel_requested, error
FROM build WHERE pkgbase_id=?1 ORDER BY rowid DESC LIMIT ?2",
)?;
- let rows = st.query_map(params![pkgbase_id, limit], |r| {
- Ok(crate::db::builds::BuildRow {
- id: r.get(0)?, pkgbase_id: r.get(1)?, candidate_id: r.get(2)?, release_id: r.get(3)?,
- kind: r.get(4)?, world_snapshot_id: r.get(5)?, build_profile: r.get(6)?, state: r.get(7)?,
- blocked_on_json: r.get(8)?, current_step: r.get(9)?, lease_owner: r.get(10)?,
- lease_expires_at: r.get(11)?, attempt: r.get(12)?, priority: r.get(13)?,
- cancel_requested: r.get::<_, i64>(14)? != 0, error: r.get(15)?,
- })
- })?;
- Ok(rows.filter_map(|r| r.ok()).collect())
+ let rows = st.query_map(params![pkgbase_id, limit], crate::db::builds::row_to_build)?;
+ // A row we cannot read is an error, not a build that quietly disappears
+ // from the package page.
+ rows.collect::<::rusqlite::Result<Vec<_>>>().map_err(Into::into)
})
}