From 1336f998bf6385dd564424c6ebd5bfd2ccf077dc Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 28 Feb 2026 17:36:40 +0300 Subject: [PATCH] fc-queue-runner: dispatch running status on build start Send "running" commit status when builds are claimed. Also fixes missing completion notifications for aggregate builds. Signed-off-by: NotAShelf Change-Id: I3b4dab8e30d6e278b7d38e2222a800a56a6a6964 --- crates/queue-runner/src/main.rs | 2 +- crates/queue-runner/src/runner_loop.rs | 35 +++++++++++++++++++++++++- crates/queue-runner/src/worker.rs | 16 ++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crates/queue-runner/src/main.rs b/crates/queue-runner/src/main.rs index 8fe4a73..f109d55 100644 --- a/crates/queue-runner/src/main.rs +++ b/crates/queue-runner/src/main.rs @@ -82,7 +82,7 @@ async fn main() -> anyhow::Result<()> { let active_builds = worker_pool.active_builds().clone(); tokio::select! { - result = fc_queue_runner::runner_loop::run(db.pool().clone(), worker_pool, poll_interval, wakeup, strict_errors, failed_paths_cache) => { + result = fc_queue_runner::runner_loop::run(db.pool().clone(), worker_pool, poll_interval, wakeup, strict_errors, failed_paths_cache, notifications_config.clone()) => { if let Err(e) = result { tracing::error!("Runner loop failed: {e}"); } diff --git a/crates/queue-runner/src/runner_loop.rs b/crates/queue-runner/src/runner_loop.rs index 8494b0b..451f032 100644 --- a/crates/queue-runner/src/runner_loop.rs +++ b/crates/queue-runner/src/runner_loop.rs @@ -1,7 +1,7 @@ use std::{sync::Arc, time::Duration}; use fc_common::{ - models::{BuildStatus, JobsetState}, + models::{Build, BuildStatus, JobsetState}, repo, }; use sqlx::PgPool; @@ -9,6 +9,21 @@ use tokio::sync::Notify; use crate::worker::WorkerPool; +/// Fetch project and commit hash for a build by traversing: +/// +/// Build -> Evaluation -> Jobset -> Project. +async fn get_project_for_build( + pool: &PgPool, + build: &Build, +) -> Option<(fc_common::models::Project, String)> { + let eval = repo::evaluations::get(pool, build.evaluation_id) + .await + .ok()?; + let jobset = repo::jobsets::get(pool, eval.jobset_id).await.ok()?; + let project = repo::projects::get(pool, jobset.project_id).await.ok()?; + Some((project, eval.commit_hash)) +} + /// Main queue runner loop. Polls for pending builds and dispatches them to /// workers. /// @@ -22,6 +37,7 @@ pub async fn run( wakeup: Arc, strict_errors: bool, failed_paths_cache: bool, + notifications_config: fc_common::config::NotificationsConfig, ) -> anyhow::Result<()> { // Reset orphaned builds from previous crashes (older than 5 minutes) match repo::builds::reset_orphaned(&pool, 300).await { @@ -68,6 +84,23 @@ pub async fn run( .await { tracing::warn!(build_id = %build.id, "Failed to complete aggregate build: {e}"); + continue; + } + + // Dispatch completion notification for aggregate build + if let Ok(updated_build) = + repo::builds::get(&pool, build.id).await + && let Some((project, commit_hash)) = + get_project_for_build(&pool, &updated_build).await + { + fc_common::notifications::dispatch_build_finished( + Some(&pool), + &updated_build, + &project, + &commit_hash, + ¬ifications_config, + ) + .await; } continue; }, diff --git a/crates/queue-runner/src/worker.rs b/crates/queue-runner/src/worker.rs index b9a79b7..4c0817a 100644 --- a/crates/queue-runner/src/worker.rs +++ b/crates/queue-runner/src/worker.rs @@ -474,6 +474,22 @@ async fn run_build( return Ok(()); } + let claimed_build = claimed.unwrap(); // Safe: we checked is_some() + + // Dispatch build started notification + if let Some((project, commit_hash)) = + get_project_for_build(pool, &claimed_build).await + { + fc_common::notifications::dispatch_build_started( + pool, + &claimed_build, + &project, + &commit_hash, + notifications_config, + ) + .await; + } + tracing::info!(build_id = %build.id, job = %build.job_name, "Starting build"); // Create a build step record