37 lines
829 B
Rust
37 lines
829 B
Rust
//! Hive-mind live tracking — track running node statuses in real time.
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::Mutex;
|
|
|
|
/// Real-time status of all running hive-mind nodes.
|
|
pub struct LiveHiveMind {
|
|
nodes: Mutex<HashMap<String, String>>,
|
|
}
|
|
|
|
impl LiveHiveMind {
|
|
pub fn new() -> Self {
|
|
LiveHiveMind {
|
|
nodes: Mutex::new(HashMap::new()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for LiveHiveMind {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl LiveHiveMind {
|
|
|
|
pub fn set_status(&self, agent_id: &str, status: &str) {
|
|
if let Ok(mut guard) = self.nodes.lock() {
|
|
guard.insert(agent_id.to_string(), status.to_string());
|
|
}
|
|
}
|
|
|
|
pub fn get_statuses(&self) -> HashMap<String, String> {
|
|
self.nodes.lock().map(|g| g.clone()).unwrap_or_default()
|
|
}
|
|
}
|