From 015360ffcfb3cf0f5a0f332e30389fde60a463b6 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 18 Feb 2026 11:30:30 +0300 Subject: [PATCH] fc-queue-runner: integrate GC pinning and machine health tracking `gc_loop` queries pinned build IDs before cleanup. `try_remote_build` calls `record_success`/`record_failure` per builder. Signed-off-by: NotAShelf Change-Id: Ia8e20ead3c83b78d787dba518c382f9a6a6a6964 --- crates/queue-runner/src/main.rs | 16 +++++++++++++--- crates/queue-runner/src/worker.rs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/queue-runner/src/main.rs b/crates/queue-runner/src/main.rs index 2a8454d..4cd817e 100644 --- a/crates/queue-runner/src/main.rs +++ b/crates/queue-runner/src/main.rs @@ -87,7 +87,7 @@ async fn main() -> anyhow::Result<()> { tracing::error!("Runner loop failed: {e}"); } } - () = gc_loop(gc_config_for_loop) => {} + () = gc_loop(gc_config_for_loop, db.pool().clone()) => {} () = failed_paths_cleanup_loop(db.pool().clone(), failed_paths_ttl, failed_paths_cache) => {} () = cancel_checker_loop(db.pool().clone(), active_builds) => {} () = shutdown_signal() => { @@ -118,7 +118,7 @@ async fn cleanup_stale_logs(log_dir: &std::path::Path) { } } -async fn gc_loop(gc_config: GcConfig) { +async fn gc_loop(gc_config: GcConfig, pool: sqlx::PgPool) { if !gc_config.enabled { return std::future::pending().await; } @@ -127,7 +127,17 @@ async fn gc_loop(gc_config: GcConfig) { loop { tokio::time::sleep(interval).await; - match gc_roots::cleanup_old_roots(&gc_config.gc_roots_dir, max_age) { + + let pinned = match repo::builds::list_pinned_ids(&pool).await { + Ok(ids) => ids, + Err(e) => { + tracing::warn!("Failed to fetch pinned build IDs for GC: {e}"); + std::collections::HashSet::new() + }, + }; + + match gc_roots::cleanup_old_roots(&gc_config.gc_roots_dir, max_age, &pinned) + { Ok(count) if count > 0 => { tracing::info!(count, "Cleaned up old GC roots"); // Optionally run nix-collect-garbage diff --git a/crates/queue-runner/src/worker.rs b/crates/queue-runner/src/worker.rs index 51b2bde..6d26c4b 100644 --- a/crates/queue-runner/src/worker.rs +++ b/crates/queue-runner/src/worker.rs @@ -427,13 +427,25 @@ async fn try_remote_build( .await; match result { - Ok(r) => return Some(r), + Ok(r) => { + if let Err(e) = + repo::remote_builders::record_success(pool, builder.id).await + { + tracing::warn!(builder = %builder.name, "Failed to record builder success: {e}"); + } + return Some(r); + }, Err(e) => { tracing::warn!( build_id = %build.id, builder = %builder.name, "Remote build failed: {e}, trying next builder" ); + if let Err(e) = + repo::remote_builders::record_failure(pool, builder.id).await + { + tracing::warn!(builder = %builder.name, "Failed to record builder failure: {e}"); + } }, } }