summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/builds.rs41
1 files changed, 36 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)
})
}