collect results, handle failing evals

This commit is contained in:
⛧-440729 [sophie] 2025-05-16 21:46:27 +02:00
parent 529c88f0fb
commit 657f324865
No known key found for this signature in database
GPG key ID: 8566000000440729
5 changed files with 166 additions and 20 deletions

View file

@ -6,10 +6,11 @@ use tokio::{
};
use crate::{
NixCiResult, NixCiResultType,
copy::CopyLoopMessage,
types::{
NixInternalLogLine, NixInternalLogLineActivity, NixInternalLogLineActivityType,
NixInternalLogLineResult, NixJob,
NixInternalLogLineResult, NixJob, NixJobEnum,
},
util::{ChildOutput, WrappedChild},
};
@ -63,7 +64,11 @@ struct BuildProgress {
reported_builds: VecDeque<BuildState>,
}
pub async fn build_loop(mut rx: Receiver<BuildLoopMessage>, copy_tx: Sender<CopyLoopMessage>) {
pub async fn build_loop(
mut rx: Receiver<BuildLoopMessage>,
copy_tx: Sender<CopyLoopMessage>,
result_tx: Sender<NixCiResult>,
) {
let mut paths_built = Vec::new();
while let Some(msg) = rx.recv().await {
let job = match msg {
@ -74,12 +79,31 @@ pub async fn build_loop(mut rx: Receiver<BuildLoopMessage>, copy_tx: Sender<Copy
}
};
tracing::info!("building {}", job.attr);
if !paths_built.contains(&job.drv_path) {
paths_built.push(job.drv_path.clone());
match run_build(job).await {
Err(e) => tracing::error!("nix build process errored! {}", e),
let NixJobEnum::Success(eval_job) = job.job else {
continue;
};
if !paths_built.contains(&eval_job.drv_path) {
paths_built.push(eval_job.drv_path.clone());
match run_build(job.attr, eval_job.drv_path.clone()).await {
Err(e) => {
let _ = result_tx
.send(NixCiResult {
r#type: NixCiResultType::Build,
path: eval_job.drv_path.clone(),
success: false,
})
.await;
tracing::error!("nix build process errored! {}", e);
}
Ok(results) => {
for result in results {
let _ = result_tx
.send(NixCiResult {
r#type: NixCiResultType::Build,
path: result.path.clone(),
success: result.result == BuildResultType::Built,
})
.await;
if let Err(e) = copy_tx.send(CopyLoopMessage::Build(result)).await {
tracing::error!("failed to enqueue package copy: {}", e);
break;
@ -91,8 +115,8 @@ pub async fn build_loop(mut rx: Receiver<BuildLoopMessage>, copy_tx: Sender<Copy
}
}
#[tracing::instrument(skip(job), fields(attr = job.attr))]
pub async fn run_build(job: NixJob) -> anyhow::Result<Vec<BuildResult>> {
#[tracing::instrument(skip(drv_path))]
pub async fn run_build(attr: String, drv_path: String) -> anyhow::Result<Vec<BuildResult>> {
let mut child = WrappedChild::new(
Command::new("nix")
.args(&[
@ -102,8 +126,8 @@ pub async fn run_build(job: NixJob) -> anyhow::Result<Vec<BuildResult>> {
"--log-format",
"internal-json",
])
.arg(format!("{}^*", job.drv_path)),
Some(format!("nix build {}", job.attr)),
.arg(format!("{}^*", drv_path)),
Some(format!("nix build {}", attr)),
)?;
let mut activities = HashMap::<u64, ActivityData>::new();
// build progress per parent as remote builds are run with a nested parent (scoped under the Realise activity id)
@ -326,7 +350,7 @@ pub async fn run_build(job: NixJob) -> anyhow::Result<Vec<BuildResult>> {
BuildResultType::Built
}
BuildState::Failed => {
tracing::warn!("derivation {} failed to build", drv_path);
tracing::error!("derivation {} failed to build", drv_path);
BuildResultType::Failed
}
_ => {