From c32905cca45972abba8d5877a714508ee91a8ebd Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 21 Jan 2024 15:43:46 -0800 Subject: [PATCH] support enable / disable components of sequence / parallel procedure --- bin/core/src/helpers/procedure.rs | 54 +++++++++++++++++++++-------- client/rs/src/entities/procedure.rs | 12 +++++-- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/bin/core/src/helpers/procedure.rs b/bin/core/src/helpers/procedure.rs index 955eb0166..747591e8f 100644 --- a/bin/core/src/helpers/procedure.rs +++ b/bin/core/src/helpers/procedure.rs @@ -9,7 +9,7 @@ use monitor_client::{ api::execute::Execution, entities::{ monitor_timestamp, - procedure::{Procedure, ProcedureConfig}, + procedure::{EnabledId, Procedure, ProcedureConfig}, update::Update, }, }; @@ -97,8 +97,14 @@ impl State { ), ) .await; - self.execute_sequence(ids, map, update).await.with_context( - || { + self + .execute_sequence( + &filter_list_by_enabled(ids), + map, + update, + ) + .await + .with_context(|| { let time = Duration::from_millis( (monitor_timestamp() - start_ts) as u64, ); @@ -106,8 +112,7 @@ impl State { "failed sequence execution after {time:?}. {} ({})", procedure.name, procedure.id ) - }, - )?; + })?; let time = Duration::from_millis( (monitor_timestamp() - start_ts) as u64, ); @@ -132,8 +137,14 @@ impl State { ), ) .await; - self.execute_parallel(ids, map, update).await.with_context( - || { + self + .execute_parallel( + &filter_list_by_enabled(ids), + map, + update, + ) + .await + .with_context(|| { let time = Duration::from_millis( (monitor_timestamp() - start_ts) as u64, ); @@ -141,8 +152,7 @@ impl State { "failed parallel execution after {time:?}. {} ({})", procedure.name, procedure.id ) - }, - )?; + })?; let time = Duration::from_millis( (monitor_timestamp() - start_ts) as u64, ); @@ -282,7 +292,10 @@ impl State { let more_ids = more .iter() - .map(|id| ObjectId::from_str(id).context("id is not ObjectId")) + .filter(|id| id.enabled) + .map(|id| { + ObjectId::from_str(&id.id).context("id is not ObjectId") + }) .collect::>>()?; let procedures = find_collect( @@ -297,11 +310,14 @@ impl State { .collect::>(); // make sure we aren't missing any procedures - for more in more { - if !procedures.contains_key(more) { - return Err(anyhow!( - "did not find a procedure with id {more}" - )); + for EnabledId { id, enabled } in more { + if !enabled { + continue; + } + if !procedures.contains_key(id) { + return Err( + anyhow!("did not find a procedure with id {id}",), + ); } } @@ -319,3 +335,11 @@ impl State { Ok(()) } } + +fn filter_list_by_enabled(list: &[EnabledId]) -> Vec { + list + .iter() + .filter(|item| item.enabled) + .map(|item| item.id.clone()) + .collect() +} diff --git a/client/rs/src/entities/procedure.rs b/client/rs/src/entities/procedure.rs index 7f629867e..6448fa695 100644 --- a/client/rs/src/entities/procedure.rs +++ b/client/rs/src/entities/procedure.rs @@ -26,6 +26,14 @@ pub struct ProcedureListItemInfo { // #[typeshare(serialized_as = "ProcedureConfig['type']")] // pub type _ProcedureConfigVariant = ProcedureConfigVariant; +/// Allows to enable / disabled procedures in the sequence / parallel vec on the fly +#[typeshare] +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct EnabledId { + pub id: String, + pub enabled: bool, +} + #[typeshare] #[derive(Serialize, Deserialize, Debug, Clone, EnumVariants)] #[variant_derive( @@ -42,9 +50,9 @@ pub struct ProcedureListItemInfo { pub enum ProcedureConfig { Execution(Execution), /// Vec - Sequence(Vec), + Sequence(Vec), /// Vec - Parallel(Vec), + Parallel(Vec), } impl From<&ProcedureConfig> for ProcedureConfigVariant {