fix: bring back to TUI
All checks were successful
Run Check Script / check (pull_request) Successful in 1m20s
All checks were successful
Run Check Script / check (pull_request) Successful in 1m20s
This commit is contained in:
@@ -9,7 +9,13 @@ use widget::{help::HelpWidget, score::ScoreListWidget};
|
||||
use std::{panic, sync::Arc, time::Duration};
|
||||
|
||||
use crossterm::event::{Event, EventStream, KeyCode, KeyEventKind};
|
||||
use harmony::{maestro::Maestro, score::Score, topology::Topology};
|
||||
use harmony::{
|
||||
instrumentation::{self, HarmonyEvent},
|
||||
inventory::Inventory,
|
||||
maestro::Maestro,
|
||||
score::Score,
|
||||
topology::Topology,
|
||||
};
|
||||
use ratatui::{
|
||||
self, Frame,
|
||||
layout::{Constraint, Layout, Position},
|
||||
@@ -39,22 +45,62 @@ pub mod tui {
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let inventory = Inventory::autoload();
|
||||
/// let topology = HAClusterTopology::autoload();
|
||||
/// let mut maestro = Maestro::new_without_initialization(inventory, topology);
|
||||
///
|
||||
/// maestro.register_all(vec![
|
||||
/// Box::new(SuccessScore {}),
|
||||
/// Box::new(ErrorScore {}),
|
||||
/// Box::new(PanicScore {}),
|
||||
/// ]);
|
||||
/// harmony_tui::init(maestro).await.unwrap();
|
||||
/// harmony_tui::run(
|
||||
/// Inventory::autoload(),
|
||||
/// HAClusterTopology::autoload(),
|
||||
/// vec![
|
||||
/// Box::new(SuccessScore {}),
|
||||
/// Box::new(ErrorScore {}),
|
||||
/// Box::new(PanicScore {}),
|
||||
/// ]
|
||||
/// ).await.unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn init<T: Topology + Send + Sync + 'static>(
|
||||
pub async fn run<T: Topology + Send + Sync + 'static>(
|
||||
inventory: Inventory,
|
||||
topology: T,
|
||||
scores: Vec<Box<dyn Score<T>>>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let handle = init_instrumentation().await;
|
||||
|
||||
let mut maestro = Maestro::initialize(inventory, topology).await.unwrap();
|
||||
maestro.register_all(scores);
|
||||
|
||||
let result = init(maestro).await;
|
||||
|
||||
let _ = tokio::try_join!(handle);
|
||||
result
|
||||
}
|
||||
|
||||
async fn init<T: Topology + Send + Sync + 'static>(
|
||||
maestro: Maestro<T>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
HarmonyTUI::new(maestro).init().await
|
||||
let result = HarmonyTUI::new(maestro).init().await;
|
||||
|
||||
instrumentation::instrument(HarmonyEvent::HarmonyFinished).unwrap();
|
||||
result
|
||||
}
|
||||
|
||||
async fn init_instrumentation() -> tokio::task::JoinHandle<()> {
|
||||
let handle = tokio::spawn(handle_harmony_events());
|
||||
|
||||
loop {
|
||||
if instrumentation::instrument(HarmonyEvent::HarmonyStarted).is_ok() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
handle
|
||||
}
|
||||
|
||||
async fn handle_harmony_events() {
|
||||
instrumentation::subscribe("Harmony TUI Logger", async |event| {
|
||||
if let HarmonyEvent::HarmonyFinished = event {
|
||||
return false;
|
||||
};
|
||||
true
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
pub struct HarmonyTUI<T: Topology> {
|
||||
|
||||
Reference in New Issue
Block a user