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 {
|
impl PaginationParams {
|
||||||
pub fn limit(&self) -> i64 {
|
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 {
|
pub fn offset(&self) -> i64 {
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,22 @@ pub async fn list_for_project(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_stats(pool: &PgPool) -> Result<BuildStats> {
|
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)
|
.fetch_optional(pool)
|
||||||
.await
|
.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
|
/// Reset builds that were left in 'running' state (orphaned by a crashed
|
||||||
|
|
|
||||||
|
|
@ -87,28 +87,29 @@ async fn evaluate_jobset(
|
||||||
"Starting evaluation cycle"
|
"Starting evaluation cycle"
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = check_disk_space(&work_dir) {
|
match check_disk_space(&work_dir) {
|
||||||
tracing::warn!(
|
Ok(info) => {
|
||||||
jobset = %jobset.name,
|
if info.is_critical() {
|
||||||
"Disk space check failed: {}. Proceeding anyway...",
|
tracing::error!(
|
||||||
e
|
jobset = %jobset.name,
|
||||||
);
|
"CRITICAL: Less than 1GB disk space available. {}",
|
||||||
}
|
info.summary()
|
||||||
|
);
|
||||||
if let Ok(info) = check_disk_space(&work_dir) {
|
} else if info.is_low() {
|
||||||
if info.is_critical() {
|
tracing::warn!(
|
||||||
tracing::error!(
|
jobset = %jobset.name,
|
||||||
jobset = %jobset.name,
|
"LOW: Less than 5GB disk space available. {}",
|
||||||
"CRITICAL: Less than 1GB disk space available. {}",
|
info.summary()
|
||||||
info.summary()
|
);
|
||||||
);
|
}
|
||||||
} else if info.is_low() {
|
},
|
||||||
|
Err(e) => {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
jobset = %jobset.name,
|
jobset = %jobset.name,
|
||||||
"LOW: Less than 5GB disk space available. {}",
|
"Disk space check failed: {}. Proceeding anyway...",
|
||||||
info.summary()
|
e
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone/fetch in a blocking task (git2 is sync) with timeout
|
// Clone/fetch in a blocking task (git2 is sync) with timeout
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ pub struct WorkerPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkerPool {
|
impl WorkerPool {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
db_pool: PgPool,
|
db_pool: PgPool,
|
||||||
workers: usize,
|
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))]
|
#[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(
|
async fn run_build(
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
build: &Build,
|
build: &Build,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue