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 <raf@notashelf.dev> Change-Id: I3b4dab8e30d6e278b7d38e2222a800a56a6a6964
This commit is contained in:
parent
1e28c31077
commit
1336f998bf
3 changed files with 51 additions and 2 deletions
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Notify>,
|
||||
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;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue