From ce0c3ba204212082a6b06678f8e53541e3b25fb4 Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Sat, 15 Jun 2024 12:54:44 +0200 Subject: [PATCH] disabling III: simplify No change in behaviour. We need to change behaviour on exit code 5. This change prepares it. CMK-17546 --- src/bin/scheduler/setup/general.rs | 2 +- src/bin/scheduler/setup/rcc.rs | 66 +++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/bin/scheduler/setup/general.rs b/src/bin/scheduler/setup/general.rs index a52dd345..28b7b968 100644 --- a/src/bin/scheduler/setup/general.rs +++ b/src/bin/scheduler/setup/general.rs @@ -7,7 +7,7 @@ use log::{debug, error}; use robotmk::results::{plan_results_directory, GeneralSetupFailures}; use robotmk::section::WriteSection; use std::collections::{HashMap, HashSet}; -use std::fs::{create_dir_all, remove_file}; +use std::fs::{create_dir_all, remove_dir_all, remove_file}; pub fn setup(global_config: &GlobalConfig, plans: Vec) -> AnyhowResult> { setup_working_directories(&global_config.working_directory, &plans)?; diff --git a/src/bin/scheduler/setup/rcc.rs b/src/bin/scheduler/setup/rcc.rs index 5567daa9..6bbdc680 100644 --- a/src/bin/scheduler/setup/rcc.rs +++ b/src/bin/scheduler/setup/rcc.rs @@ -271,33 +271,61 @@ fn holotree_init( let mut failed_plans: HashMap = HashMap::new(); for (session, plans) in plans_by_sessions(plans) { - let session_id = format!( - "{}_{}", - "holotree_initialization", + debug!("Running {} for `{}`", command_spec, &session); + let session_id = &format!( + "holotree_initialization_{}", match &session { Session::Current(_) => "current_user".into(), Session::User(user_session) => format!("user_{}", user_session.user_name), } ); - - debug!("Running {} for `{}`", command_spec, &session); - match execute_run_spec_in_session( - &session, - &RunSpec { - id: &format!("robotmk_{session_id}"), - command_spec: &command_spec, - base_path: &rcc_setup_working_directory(&global_config.working_directory) - .join(session_id), - timeout: 120, - cancellation_token: &global_config.cancellation_token, - }, - )? { - Some(error_msg) => { + let run_spec = &RunSpec { + id: &format!("robotmk_{session_id}"), + command_spec: &command_spec, + base_path: &rcc_setup_working_directory(&global_config.working_directory) + .join(session_id), + timeout: 120, + cancellation_token: &global_config.cancellation_token, + }; + match session.run(run_spec) { + Ok(Outcome::Completed(0)) => { + debug!("{} for `{session}` successful", run_spec.command_spec); + succesful_plans.extend(plans); + } + Ok(Outcome::Completed(_)) => { + error!( + "{} for `{session}` exited non-successfully", + run_spec.command_spec + ); + let error_message = format!( + "Non-zero exit code, see {} for stdio logs", + run_spec.base_path + ); for plan in plans { - failed_plans.insert(plan.id, error_msg.clone()); + failed_plans.insert(plan.id, error_message.clone()); + } + } + Ok(Outcome::Timeout) => { + error!("{} for `{session}` timed out", run_spec.command_spec); + for plan in plans { + failed_plans.insert(plan.id, "Timeout".to_string()); + } + } + Ok(Outcome::Cancel) => { + error!("{} for `{session}` cancelled", run_spec.command_spec); + return Err(Cancelled {}); + } + Err(error) => { + let error = error.context(format!( + "Failed to run {} for `{session}`", + run_spec.command_spec + )); + let error = log_and_return_error(error); + let error_message = format!("{error:?}"); + for plan in plans { + failed_plans.insert(plan.id, error_message.clone()); } } - None => succesful_plans.extend(plans), } }