various: eliminate redundant disk check; improve error handling
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1f37cc60380790bc1bf11f143194ad116a6a6964
This commit is contained in:
parent
d620ec5454
commit
1c18306822
5 changed files with 39 additions and 23 deletions
2
crates/common/migrations/009_builds_job_name_index.sql
Normal file
2
crates/common/migrations/009_builds_job_name_index.sql
Normal file
|
|
@ -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);
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -142,11 +142,22 @@ pub async fn list_for_project(
|
|||
}
|
||||
|
||||
pub async fn get_stats(pool: &PgPool) -> Result<BuildStats> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -87,15 +87,8 @@ 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) {
|
||||
match check_disk_space(&work_dir) {
|
||||
Ok(info) => {
|
||||
if info.is_critical() {
|
||||
tracing::error!(
|
||||
jobset = %jobset.name,
|
||||
|
|
@ -109,6 +102,14 @@ async fn evaluate_jobset(
|
|||
info.summary()
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
jobset = %jobset.name,
|
||||
"Disk space check failed: {}. Proceeding anyway...",
|
||||
e
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
// Clone/fetch in a blocking task (git2 is sync) with timeout
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue