refactor: Remove InterpretStatus/Error & Outcome from Topology

This commit is contained in:
Ian Letourneau
2025-08-06 22:29:00 -04:00
parent 440c1bce12
commit f876b5e67b
15 changed files with 361 additions and 141 deletions

View File

@@ -1,4 +1,7 @@
use harmony::instrumentation::{self, HarmonyEvent};
use harmony::{
instrumentation::{self, HarmonyEvent},
topology::TopologyStatus,
};
use indicatif::{MultiProgress, ProgressBar};
use indicatif_log_bridge::LogWrapper;
use std::{
@@ -47,52 +50,90 @@ async fn handle_events() {
match event {
HarmonyEvent::HarmonyStarted => {}
HarmonyEvent::PrepareTopologyStarted { topology: name } => {
let section = progress::new_section(format!(
"{} Preparing environment: {name}...",
crate::theme::EMOJI_TOPOLOGY,
));
(*sections).insert(name, section);
}
HarmonyEvent::TopologyPrepared {
topology: name,
outcome,
HarmonyEvent::TopologyStateChanged {
topology,
status,
message,
} => {
let section = (*sections).get(&name).unwrap();
let progress = progress::add_spinner(section, "".into());
let section_key = topology_key(&topology);
match outcome.status {
harmony::interpret::InterpretStatus::SUCCESS => {
progress::success(section, Some(progress), outcome.message);
match status {
TopologyStatus::Queued => {}
TopologyStatus::Preparing => {
let section = progress::new_section(format!(
"{} Preparing environment: {topology}...",
crate::theme::EMOJI_TOPOLOGY,
));
(*sections).insert(section_key, section);
}
harmony::interpret::InterpretStatus::FAILURE => {
progress::error(section, Some(progress), outcome.message);
TopologyStatus::Success => {
let section = (*sections).get(&section_key).unwrap();
let progress = progress::add_spinner(section, "".into());
progress::success(
section,
Some(progress),
message.unwrap_or("".into()),
);
(*sections).remove(&section_key);
}
harmony::interpret::InterpretStatus::RUNNING => todo!(),
harmony::interpret::InterpretStatus::QUEUED => todo!(),
harmony::interpret::InterpretStatus::BLOCKED => todo!(),
harmony::interpret::InterpretStatus::NOOP => {
progress::skip(section, Some(progress), outcome.message);
TopologyStatus::Noop => {
let section = (*sections).get(&section_key).unwrap();
let progress = progress::add_spinner(section, "".into());
progress::skip(
section,
Some(progress),
message.unwrap_or("".into()),
);
(*sections).remove(&section_key);
}
TopologyStatus::Error => {
let section = (*sections).get(&section_key).unwrap();
let progress = progress::add_spinner(section, "".into());
progress::error(
section,
Some(progress),
message.unwrap_or("".into()),
);
(*sections).remove(&section_key);
}
}
}
HarmonyEvent::InterpretExecutionStarted {
interpret: name,
topology,
interpret,
message,
} => {
let section = (*sections).get(&topology).unwrap();
let section_key = if (*sections).contains_key(&topology_key(&topology)) {
topology_key(&topology)
} else {
interpret_key(&interpret)
};
let section = (*sections).get(&section_key).unwrap();
let progress_bar = progress::add_spinner(section, message);
(*progress_bars).insert(name, progress_bar);
(*progress_bars).insert(interpret_key(&interpret), progress_bar);
}
HarmonyEvent::InterpretExecutionFinished {
topology,
interpret: name,
interpret,
outcome,
} => {
let section = (*sections).get(&topology).unwrap();
let progress_bar = (*progress_bars).get(&name).cloned();
let has_topology = (*sections).contains_key(&topology_key(&topology));
let section_key = if has_topology {
topology_key(&topology)
} else {
interpret_key(&interpret)
};
let section = (*sections).get(&section_key).unwrap();
let progress_bar =
(*progress_bars).get(&interpret_key(&interpret)).cloned();
let _ = section.clear();
@@ -105,7 +146,9 @@ async fn handle_events() {
}
}
(*progress_bars).remove(&name);
if !has_topology {
(*progress_bars).remove(&section_key);
}
}
}
true
@@ -114,3 +157,11 @@ async fn handle_events() {
})
.await;
}
fn topology_key(topology: &str) -> String {
format!("topology-{topology}")
}
fn interpret_key(interpret: &str) -> String {
format!("interpret-{interpret}")
}