treewide: address all clippy lints
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5cf55cc4cb558c3f9f764c71224e87176a6a6964
This commit is contained in:
parent
967d51e867
commit
a127f3f62c
63 changed files with 1790 additions and 1089 deletions
|
|
@ -20,6 +20,11 @@ use tokio::sync::Notify;
|
|||
use tracing::info;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Main evaluator loop. Polls jobsets and runs nix evaluations.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns error if evaluation cycle fails and `strict_errors` is enabled.
|
||||
pub async fn run(
|
||||
pool: PgPool,
|
||||
config: EvaluatorConfig,
|
||||
|
|
@ -57,13 +62,10 @@ async fn run_cycle(
|
|||
let ready: Vec<_> = active
|
||||
.into_iter()
|
||||
.filter(|js| {
|
||||
match js.last_checked_at {
|
||||
Some(last) => {
|
||||
let elapsed = (now - last).num_seconds();
|
||||
elapsed >= i64::from(js.check_interval)
|
||||
},
|
||||
None => true, // Never checked, evaluate now
|
||||
}
|
||||
js.last_checked_at.is_none_or(|last| {
|
||||
let elapsed = (now - last).num_seconds();
|
||||
elapsed >= i64::from(js.check_interval)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -91,11 +93,10 @@ async fn run_cycle(
|
|||
|| msg.contains("sqlite")
|
||||
{
|
||||
tracing::error!(
|
||||
"DISK SPACE ISSUE DETECTED: Evaluation failed due to disk space \
|
||||
problems. Please free up space on the server:\n- Run \
|
||||
`nix-collect-garbage -d` to clean the Nix store\n- Clear \
|
||||
/tmp/fc-evaluator directory\n- Check build logs directory if \
|
||||
configured"
|
||||
"Evaluation failed due to disk space problems. Please free up \
|
||||
space on the server:\n- Run `nix-collect-garbage -d` to clean \
|
||||
the Nix store\n- Clear /tmp/fc-evaluator directory\n- Check \
|
||||
build logs directory if configured"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -129,13 +130,13 @@ async fn evaluate_jobset(
|
|||
if info.is_critical() {
|
||||
tracing::error!(
|
||||
jobset = %jobset.name,
|
||||
"CRITICAL: Less than 1GB disk space available. {}",
|
||||
"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. {}",
|
||||
"Less than 5GB disk space available. {}",
|
||||
info.summary()
|
||||
);
|
||||
}
|
||||
|
|
@ -277,13 +278,12 @@ async fn evaluate_jobset(
|
|||
);
|
||||
}
|
||||
return Ok(());
|
||||
} else {
|
||||
info!(
|
||||
"Evaluation completed but has 0 builds, re-running nix evaluation \
|
||||
jobset={} commit={}",
|
||||
jobset.name, commit_hash
|
||||
);
|
||||
}
|
||||
info!(
|
||||
"Evaluation completed but has 0 builds, re-running nix evaluation \
|
||||
jobset={} commit={}",
|
||||
jobset.name, commit_hash
|
||||
);
|
||||
}
|
||||
existing
|
||||
},
|
||||
|
|
@ -420,12 +420,10 @@ async fn create_builds_from_eval(
|
|||
for dep_drv in input_drvs.keys() {
|
||||
if let Some(&dep_build_id) = drv_to_build.get(dep_drv)
|
||||
&& dep_build_id != build_id
|
||||
{
|
||||
if let Err(e) =
|
||||
&& let Err(e) =
|
||||
repo::build_dependencies::create(pool, build_id, dep_build_id).await
|
||||
{
|
||||
tracing::warn!(build_id = %build_id, dep = %dep_build_id, "Failed to create build dependency: {e}");
|
||||
}
|
||||
{
|
||||
tracing::warn!(build_id = %build_id, dep = %dep_build_id, "Failed to create build dependency: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -435,12 +433,10 @@ async fn create_builds_from_eval(
|
|||
for constituent_name in constituents {
|
||||
if let Some(&dep_build_id) = name_to_build.get(constituent_name)
|
||||
&& dep_build_id != build_id
|
||||
{
|
||||
if let Err(e) =
|
||||
&& let Err(e) =
|
||||
repo::build_dependencies::create(pool, build_id, dep_build_id).await
|
||||
{
|
||||
tracing::warn!(build_id = %build_id, dep = %dep_build_id, "Failed to create constituent dependency: {e}");
|
||||
}
|
||||
{
|
||||
tracing::warn!(build_id = %build_id, dep = %dep_build_id, "Failed to create constituent dependency: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -450,7 +446,7 @@ async fn create_builds_from_eval(
|
|||
}
|
||||
|
||||
/// Compute a deterministic hash over the commit and all jobset inputs.
|
||||
/// Used for evaluation caching — skip re-eval when inputs haven't changed.
|
||||
/// Used for evaluation caching, so skip re-eval when inputs haven't changed.
|
||||
fn compute_inputs_hash(commit_hash: &str, inputs: &[JobsetInput]) -> String {
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
|
|
@ -480,6 +476,20 @@ async fn check_declarative_config(
|
|||
repo_path: &std::path::Path,
|
||||
project_id: Uuid,
|
||||
) {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DeclarativeConfig {
|
||||
jobsets: Option<Vec<DeclarativeJobset>>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DeclarativeJobset {
|
||||
name: String,
|
||||
nix_expression: String,
|
||||
flake_mode: Option<bool>,
|
||||
check_interval: Option<i32>,
|
||||
enabled: Option<bool>,
|
||||
}
|
||||
|
||||
let config_path = repo_path.join(".fc.toml");
|
||||
let alt_config_path = repo_path.join(".fc/config.toml");
|
||||
|
||||
|
|
@ -502,20 +512,6 @@ async fn check_declarative_config(
|
|||
},
|
||||
};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DeclarativeConfig {
|
||||
jobsets: Option<Vec<DeclarativeJobset>>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DeclarativeJobset {
|
||||
name: String,
|
||||
nix_expression: String,
|
||||
flake_mode: Option<bool>,
|
||||
check_interval: Option<i32>,
|
||||
enabled: Option<bool>,
|
||||
}
|
||||
|
||||
let config: DeclarativeConfig = match toml::from_str(&content) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ use git2::Repository;
|
|||
///
|
||||
/// If `branch` is `Some`, resolve `refs/remotes/origin/<branch>` instead of
|
||||
/// HEAD.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns error if git operations fail.
|
||||
#[tracing::instrument(skip(work_dir))]
|
||||
pub fn clone_or_fetch(
|
||||
url: &str,
|
||||
|
|
@ -20,7 +24,7 @@ pub fn clone_or_fetch(
|
|||
|
||||
let repo = if is_fetch {
|
||||
let repo = Repository::open(&repo_path)?;
|
||||
// Fetch origin — scope the borrow so `remote` is dropped before we move
|
||||
// Fetch origin. Scope the borrow so `remote` is dropped before we move
|
||||
// `repo`
|
||||
{
|
||||
let mut remote = repo.find_remote("origin")?;
|
||||
|
|
@ -34,12 +38,11 @@ pub fn clone_or_fetch(
|
|||
// Resolve commit from remote refs (which are always up-to-date after fetch).
|
||||
// When no branch is specified, detect the default branch from local HEAD's
|
||||
// tracking target.
|
||||
let branch_name = match branch {
|
||||
Some(b) => b.to_string(),
|
||||
None => {
|
||||
let head = repo.head()?;
|
||||
head.shorthand().unwrap_or("master").to_string()
|
||||
},
|
||||
let branch_name = if let Some(b) = branch {
|
||||
b.to_string()
|
||||
} else {
|
||||
let head = repo.head()?;
|
||||
head.shorthand().unwrap_or("master").to_string()
|
||||
};
|
||||
|
||||
let remote_ref = format!("refs/remotes/origin/{branch_name}");
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ pub fn parse_eval_output(stdout: &str) -> EvalResult {
|
|||
/// Evaluate nix expressions and return discovered jobs.
|
||||
/// If `flake_mode` is true, uses nix-eval-jobs with --flake flag.
|
||||
/// If `flake_mode` is false, evaluates a legacy expression file.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns error if nix evaluation command fails or times out.
|
||||
#[tracing::instrument(skip(config, inputs), fields(flake_mode, nix_expression))]
|
||||
pub async fn evaluate(
|
||||
repo_path: &Path,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! Tests for the git clone/fetch module.
|
||||
//! Uses git2 to create a temporary repository, then exercises clone_or_fetch.
|
||||
//! Uses git2 to create a temporary repository, then exercises `clone_or_fetch`.
|
||||
|
||||
use git2::{Repository, Signature};
|
||||
use tempfile::TempDir;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue