mirror of
https://github.com/moghtech/komodo.git
synced 2026-07-19 00:52:12 -05:00
support enable / disable components of sequence / parallel procedure
This commit is contained in:
@@ -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::<anyhow::Result<Vec<_>>>()?;
|
||||
|
||||
let procedures = find_collect(
|
||||
@@ -297,11 +310,14 @@ impl State {
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
// 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<String> {
|
||||
list
|
||||
.iter()
|
||||
.filter(|item| item.enabled)
|
||||
.map(|item| item.id.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -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<ProcedureId>
|
||||
Sequence(Vec<String>),
|
||||
Sequence(Vec<EnabledId>),
|
||||
/// Vec<ProdecureId>
|
||||
Parallel(Vec<String>),
|
||||
Parallel(Vec<EnabledId>),
|
||||
}
|
||||
|
||||
impl From<&ProcedureConfig> for ProcedureConfigVariant {
|
||||
|
||||
Reference in New Issue
Block a user