Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed Mar 13, 2024
1 parent 5b824e7 commit 60fb9a2
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ pub struct ProcessingArgs<'a> {
pub message_tx: Option<mpsc::Sender<message::Message>>,
}

fn send_message(
message_tx: &Option<mpsc::Sender<message::Message>>,
status: message::Status,
id: usize,
path: String,
) {
if let Some(tx) = message_tx {
tx.send(message::Message { status, id, path }).unwrap();
}
}

fn process(args: ProcessingArgs) -> Result<()> {
log::debug!("Processing derivation: {:?}", args.attribute_path);

// Inform the calling thread that we are starting to process the derivation
if let Some(message_tx) = &args.message_tx {
message_tx
.send(message::Message {
status: message::Status::Started,
id: rayon::current_thread_index().unwrap(),
path: args.attribute_path.clone(),
})
.unwrap();
}
send_message(
&args.message_tx,
message::Status::Started,
rayon::current_thread_index().unwrap(),
args.attribute_path.clone(),
);

let description = nix::describe_derivation(
args.flake_ref,
Expand All @@ -84,15 +92,12 @@ fn process(args: ProcessingArgs) -> Result<()> {
)?;

// Inform the calling thread that we have described the derivation
if let Some(message_tx) = &args.message_tx {
message_tx
.send(message::Message {
status: message::Status::Completed,
id: rayon::current_thread_index().unwrap(),
path: description.attribute_path.clone(),
})
.unwrap();
}
send_message(
&args.message_tx,
message::Status::Completed,
rayon::current_thread_index().unwrap(),
description.attribute_path.clone(),
);

// Send the DerivationDescription to the main thread
args.tx.send(description.clone())?;
Expand Down Expand Up @@ -125,15 +130,12 @@ fn process(args: ProcessingArgs) -> Result<()> {

// Inform calling thread that the derivation was skipped if
// requested.
if let Some(message_tx) = &args.message_tx {
message_tx
.send(message::Message {
status: message::Status::Skipped,
id: rayon::current_thread_index().unwrap(),
path: build_input.attribute_path.clone(),
})
.unwrap();
}
send_message(
&args.message_tx,
message::Status::Skipped,
rayon::current_thread_index().unwrap(),
build_input.attribute_path.clone(),
);

return Ok(());
}
Expand Down

0 comments on commit 60fb9a2

Please sign in to comment.