summaryrefslogtreecommitdiffstats
path: root/src/db/builds.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 08:47:27 +0000
committeraur-build <aur-build@localhost>2026-11-18 08:47:27 +0000
commit2c5a660213ae5f9f6f12d9787c5195e2c2127e6d (patch)
tree602453277de22abf2dabc2501f2f69f2afea6e0e /src/db/builds.rs
parente27e90aa82b6c878e34b94a6fa238836f497b1c3 (diff)
downloadaur-build-2c5a660213ae5f9f6f12d9787c5195e2c2127e6d.tar.gz
aur-build-2c5a660213ae5f9f6f12d9787c5195e2c2127e6d.zip
pipeline: a real process kill, and the failure state the UI must show (§8.4, I5)
The crash-resume invariant was only ever simulated before: an in-process fault hook returns an error, and an error can be caught, unwound and cleaned up by accident. So the shims gained AUR_SHIM_KILL_PARENT — the named tool SIGKILLs the process running the pipeline, mid-step, with no Drop and no atexit. The test spawns the real aur-build binary, watches it die of SIGKILL inside the build step, and then asserts the things that matter: - the database is intact, because no transaction ever spans a build step - the completed steps are checkpointed succeeded and the running one is recorded running - after the lease expires the reaper requeues it and marks the step interrupted - resuming publishes exactly one release, and the shim invocation log proves mkarchroot ran once, makechrootpkg twice (crash + resume, not twice per attempt) and repo-add once **This found a real bug.** reap_expired only matched state='leased', but a worker sets state='running' the moment it starts a step, so a process that dies mid-step leaves a running row — and every real crash would have been stranded forever. The reaper now reaps leased and running. Also §8.4's other half, which was a comment rather than a feature: a failed build must not leave the old version looking healthy. db::approved_but_unbuilt finds approvals whose build failed and never published, and Attention and the package page now say 'v2 approved, build failed, index still serving v1' with a link to the log. Retrying is an explicit, audited POST, not something the system does to itself. Cancellation is asserted to be cooperative at a step boundary: a cancelled build runs no steps, publishes nothing, and is not counted as a failure.
Diffstat (limited to 'src/db/builds.rs')
-rw-r--r--src/db/builds.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/db/builds.rs b/src/db/builds.rs
index 0a7013c..27fa23b 100644
--- a/src/db/builds.rs
+++ b/src/db/builds.rs
@@ -161,13 +161,17 @@ pub fn extend_lease(db: &Db, id: &str, lease_secs: i64) -> Result<()> {
/// Reaper pass (§8.2): expired leases go back to the queue and their in-flight
/// step is marked interrupted, so the checkpoint decides where it resumes.
+///
+/// Both `leased` and `running` are reaped: a worker sets `running` as soon as it
+/// starts a step, so a process that dies mid-step leaves a `running` row, not a
+/// `leased` one. Reaping only `leased` would strand every real crash.
pub fn reap_expired(db: &Db) -> Result<usize> {
let now = time::now();
db.writer.tx(move |tx| {
let ids: Vec<String> = {
let mut stmt = tx.prepare(
- "SELECT id FROM build WHERE state='leased' AND lease_expires_at IS NOT NULL
- AND lease_expires_at < ?1",
+ "SELECT id FROM build WHERE state IN ('leased','running')
+ AND lease_expires_at IS NOT NULL AND lease_expires_at < ?1",
)?;
let rows = stmt.query_map(params![now], |r| r.get::<_, String>(0))?;
rows.filter_map(|r| r.ok()).collect()
@@ -484,3 +488,24 @@ pub fn requeue_transient(db: &Db, id: &str) -> Result<()> {
Ok(())
})
}
+
+/// Explicitly retry a failed build (§8.4). This is a human decision, not a
+/// policy: the failed step is put back to pending so it runs again, everything
+/// that succeeded stays checkpointed, and the attempt counter keeps counting.
+pub fn retry(db: &Db, id: &str) -> Result<()> {
+ let id = id.to_string();
+ let at = time::now();
+ db.writer.tx(move |tx| {
+ tx.execute(
+ "UPDATE build_step SET status='pending', error=NULL, started_at=NULL, finished_at=NULL
+ WHERE build_id=?1 AND status IN ('failed','interrupted')",
+ params![id],
+ )?;
+ tx.execute(
+ "UPDATE build SET state='queued', error=NULL, cancel_requested=0,
+ lease_owner=NULL, lease_expires_at=NULL, updated_at=?2 WHERE id=?1",
+ params![id, at],
+ )?;
+ Ok(())
+ })
+}