From 1c183068228eb50cbd331117eabc624d4ba22353 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 5 Feb 2026 22:48:02 +0300 Subject: [PATCH] various: eliminate redundant disk check; improve error handling Signed-off-by: NotAShelf Change-Id: I1f37cc60380790bc1bf11f143194ad116a6a6964 --- .../migrations/009_builds_job_name_index.sql | 2 + crates/common/src/models.rs | 2 +- crates/common/src/repo/builds.rs | 17 ++++++-- crates/evaluator/src/eval_loop.rs | 39 ++++++++++--------- crates/queue-runner/src/worker.rs | 2 + 5 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 crates/common/migrations/009_builds_job_name_index.sql diff --git a/crates/common/migrations/009_builds_job_name_index.sql b/crates/common/migrations/009_builds_job_name_index.sql new file mode 100644 index 0000000..67a48b9 --- /dev/null +++ b/crates/common/migrations/009_builds_job_name_index.sql @@ -0,0 +1,2 @@ +-- Add index on builds.job_name for ILIKE queries in list_filtered +CREATE INDEX IF NOT EXISTS idx_builds_job_name ON builds (job_name); diff --git a/crates/common/src/models.rs b/crates/common/src/models.rs index f17cc07..3d1dba7 100644 --- a/crates/common/src/models.rs +++ b/crates/common/src/models.rs @@ -294,7 +294,7 @@ pub struct PaginationParams { impl PaginationParams { pub fn limit(&self) -> i64 { - self.limit.unwrap_or(50).min(200).max(1) + self.limit.unwrap_or(50).clamp(1, 200) } pub fn offset(&self) -> i64 { diff --git a/crates/common/src/repo/builds.rs b/crates/common/src/repo/builds.rs index e06620a..6087d60 100644 --- a/crates/common/src/repo/builds.rs +++ b/crates/common/src/repo/builds.rs @@ -142,11 +142,22 @@ pub async fn list_for_project( } pub async fn get_stats(pool: &PgPool) -> Result { - sqlx::query_as::<_, BuildStats>("SELECT * FROM build_stats") + match sqlx::query_as::<_, BuildStats>("SELECT * FROM build_stats") .fetch_optional(pool) .await - .map_err(CiError::Database) - .map(|opt| opt.unwrap_or_default()) + { + Ok(Some(stats)) => Ok(stats), + Ok(None) => { + tracing::warn!( + "build_stats view returned no rows, returning default stats" + ); + Ok(BuildStats::default()) + }, + Err(e) => { + tracing::error!(error = %e, "Failed to fetch build stats"); + Err(CiError::Database(e)) + }, + } } /// Reset builds that were left in 'running' state (orphaned by a crashed diff --git a/crates/evaluator/src/eval_loop.rs b/crates/evaluator/src/eval_loop.rs index 7c403f6..d2e1e45 100644 --- a/crates/evaluator/src/eval_loop.rs +++ b/crates/evaluator/src/eval_loop.rs @@ -87,28 +87,29 @@ async fn evaluate_jobset( "Starting evaluation cycle" ); - if let Err(e) = check_disk_space(&work_dir) { - tracing::warn!( - jobset = %jobset.name, - "Disk space check failed: {}. Proceeding anyway...", - e - ); - } - - if let Ok(info) = check_disk_space(&work_dir) { - if info.is_critical() { - tracing::error!( - jobset = %jobset.name, - "CRITICAL: Less than 1GB disk space available. {}", - info.summary() - ); - } else if info.is_low() { + match check_disk_space(&work_dir) { + Ok(info) => { + if info.is_critical() { + tracing::error!( + jobset = %jobset.name, + "CRITICAL: Less than 1GB disk space available. {}", + info.summary() + ); + } else if info.is_low() { + tracing::warn!( + jobset = %jobset.name, + "LOW: Less than 5GB disk space available. {}", + info.summary() + ); + } + }, + Err(e) => { tracing::warn!( jobset = %jobset.name, - "LOW: Less than 5GB disk space available. {}", - info.summary() + "Disk space check failed: {}. Proceeding anyway...", + e ); - } + }, } // Clone/fetch in a blocking task (git2 is sync) with timeout diff --git a/crates/queue-runner/src/worker.rs b/crates/queue-runner/src/worker.rs index b6f8371..5825e8f 100644 --- a/crates/queue-runner/src/worker.rs +++ b/crates/queue-runner/src/worker.rs @@ -30,6 +30,7 @@ pub struct WorkerPool { } impl WorkerPool { + #[allow(clippy::too_many_arguments)] pub fn new( db_pool: PgPool, workers: usize, @@ -277,6 +278,7 @@ async fn try_remote_build( } #[tracing::instrument(skip(pool, build, work_dir, log_config, gc_config, notifications_config, signing_config, cache_upload_config), fields(build_id = %build.id, job = %build.job_name))] +#[allow(clippy::too_many_arguments)] async fn run_build( pool: &PgPool, build: &Build,