diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/db/builds.rs | 41 | ||||
| -rw-r--r-- | src/http/render.rs | 3 | ||||
| -rw-r--r-- | src/http/routes.rs | 1 | ||||
| -rw-r--r-- | src/watch/detect.rs | 29 |
4 files changed, 69 insertions, 5 deletions
diff --git a/src/db/builds.rs b/src/db/builds.rs index 27fa23b..3770746 100644 --- a/src/db/builds.rs +++ b/src/db/builds.rs @@ -221,12 +221,43 @@ pub fn block_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> { } /// Re-check blocked builds whenever a publish lands (§10.4). +/// Requeue blocked builds whose blocking packages have since arrived (§10.4). +/// +/// Not "requeue everything that is blocked": the dispatcher calls this every +/// pass, and requeueing a build that will immediately block again is a busy loop +/// that burns a claim and a plan step each tick. A build only goes back on the +/// queue when every name it is waiting for is actually in the index now. pub fn requeue_blocked(db: &Db) -> Result<usize> { - db.writer.tx(|tx| { - let n = tx.execute( - "UPDATE build SET state='queued', updated_at=?1 WHERE state='blocked_missing_dep'", - params![time::now()], - )?; + let now = time::now(); + db.writer.tx(move |tx| { + let rows: Vec<(String, String)> = { + let mut stmt = tx.prepare("SELECT id, blocked_on_json FROM build WHERE state='blocked_missing_dep'")?; + let out = stmt + .query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))? + .filter_map(|x| x.ok()) + .collect(); + out + }; + let mut n = 0; + for (id, blocked_on) in rows { + let waiting: Vec<String> = serde_json::from_str(&blocked_on).unwrap_or_default(); + let satisfied = waiting.iter().all(|name| { + tx.query_row( + "SELECT count(*) FROM package WHERE name=?1 AND state='in_index'", + params![name], + |r| r.get::<_, i64>(0), + ) + .unwrap_or(0) + > 0 + }); + if satisfied && !waiting.is_empty() { + tx.execute( + "UPDATE build SET state='queued', blocked_on_json='[]', updated_at=?1 WHERE id=?2", + params![now, id], + )?; + n += 1; + } + } Ok(n) }) } diff --git a/src/http/render.rs b/src/http/render.rs index 057ea14..ca3ba51 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -140,6 +140,9 @@ pub struct ReviewHead { pub risk: String, pub signals: Vec<String>, pub missing_deps: Vec<String>, + /// §10.3: "approving this marks N packages stale" — the packages of ours + /// whose own recipes name one of the packages this candidate produces. + pub dependents: Vec<String>, pub revision: i64, pub aur_commit: String, pub aur_commit_short: String, diff --git a/src/http/routes.rs b/src/http/routes.rs index 177ffcd..26aaa89 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -284,6 +284,7 @@ fn review_body( risk: c.risk_level.clone(), signals: c.risk_signals(), missing_deps: c.missing_deps(), + dependents: crate::watch::staleness::dependents_of(db, &c.pkgbase).unwrap_or_default(), revision: c.revision, aur_commit: snapshot.as_ref().map(|s| s.aur_commit.clone()).unwrap_or_default(), aur_commit_short: snapshot diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 55b7543..3134e19 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -258,6 +258,35 @@ fn score( if let Ok(a) = crate::review::risk::assess(db, cfg, pb, recipe, digests, accepted) { let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals); } + // Record now what would block the build later, using the same rule the plan + // step uses. A reviewer approving a package whose dependencies we have not + // published yet should see that before they approve it, not as a blocked + // build afterwards (§10.4). + let missing = missing_deps(db, pb, recipe); + let _ = crate::review::candidates::set_missing_deps(db, id, &missing); +} + +/// Dependencies that are ours to publish but are not in the index yet. +fn missing_deps(db: &Db, pb: &Pkgbase, recipe: &Recipe) -> Vec<String> { + let ours = match db::our_package_names(db) { + Ok(o) => o, + Err(_) => return Vec::new(), + }; + let mut out = Vec::new(); + for dep in crate::pkgver::dep_names(&recipe.depends) { + if ours.contains(&dep) || dep == pb.name || recipe.pkgnames.contains(&dep) { + continue; + } + let ours_to_publish = db::get_subscription(db, &dep) + .map(|s| s.is_some()) + .unwrap_or(false) + || db::get_pkgbase(db, &dep).map(|p| p.is_some()).unwrap_or(false); + if ours_to_publish { + out.push(dep); + } + } + out.sort(); + out } fn outcome_of(up: Upsert) -> Outcome { |
