diff --git a/bin/core/src/api/execute/procedure.rs b/bin/core/src/api/execute/procedure.rs index 3f5488d52..afca00d91 100644 --- a/bin/core/src/api/execute/procedure.rs +++ b/bin/core/src/api/execute/procedure.rs @@ -32,7 +32,7 @@ impl Resolve for State { fn resolve_inner( procedure: String, user: User, - update: Update, + mut update: Update, ) -> Pin< Box< dyn std::future::Future> + Send, @@ -46,6 +46,14 @@ fn resolve_inner( ) .await?; + // Need to push the initial log, as execute_procedure + // assumes first log is already created + // and will panic otherwise. + update.push_simple_log( + "execute_procedure", + format!("executing procedure {}", procedure.name), + ); + // get the action state for the procedure (or insert default). let action_state = action_states() .procedure diff --git a/bin/core/src/helpers/procedure.rs b/bin/core/src/helpers/procedure.rs index 9bc743a3e..579eb700a 100644 --- a/bin/core/src/helpers/procedure.rs +++ b/bin/core/src/helpers/procedure.rs @@ -11,12 +11,13 @@ use monitor_client::{ }; use resolver_api::Resolve; use tokio::sync::Mutex; +use tracing::Instrument; use crate::{api::execute::ExecuteRequest, state::State}; use super::update::{init_execution_update, update_update}; -#[instrument] +#[instrument(skip_all)] pub async fn execute_procedure( procedure: &Procedure, update: &Mutex, @@ -65,7 +66,39 @@ pub async fn execute_procedure( Ok(()) } -#[instrument] +#[instrument(skip(update))] +async fn execute_stage( + executions: Vec, + parent_id: &str, + parent_name: &str, + update: &Mutex, +) -> anyhow::Result<()> { + let futures = executions.into_iter().map(|execution| async move { + let now = Instant::now(); + add_line_to_update(update, &format!("executing: {execution:?}")) + .await; + let fail_log = format!("failed on {execution:?}"); + let res = + execute_execution(execution.clone(), parent_id, parent_name) + .await + .context(fail_log); + add_line_to_update( + update, + &format!( + "finished execution in {:?}: {execution:?}", + now.elapsed() + ), + ) + .await; + res + }); + join_all(futures) + .await + .into_iter() + .collect::>()?; + Ok(()) +} + async fn execute_execution( execution: Execution, // used to prevent recursive procedure @@ -224,39 +257,6 @@ async fn execute_execution( } } -#[instrument(skip(update))] -async fn execute_stage( - executions: Vec, - parent_id: &str, - parent_name: &str, - update: &Mutex, -) -> anyhow::Result<()> { - let futures = executions.into_iter().map(|execution| async move { - let now = Instant::now(); - add_line_to_update(update, &format!("executing: {execution:?}")) - .await; - let fail_log = format!("failed on {execution:?}"); - let res = - execute_execution(execution.clone(), parent_id, parent_name) - .await - .context(fail_log); - add_line_to_update( - update, - &format!( - "finished execution in {:?}: {execution:?}", - now.elapsed() - ), - ) - .await; - res - }); - join_all(futures) - .await - .into_iter() - .collect::>()?; - Ok(()) -} - /// ASSUMES FIRST LOG IS ALREADY CREATED #[instrument(level = "debug")] async fn add_line_to_update(update: &Mutex, line: &str) {