use super::CommandExecutor;
use crate::client::result::{CommandResult, HealthReport};
const STATUS_UNREACHABLE: &str = "unreachable";
impl CommandExecutor {
pub(super) async fn health(&self) -> CommandResult {
let url = self.client().base_url().to_string();
let snapshot = match self.client().health_snapshot().await {
Ok(snapshot) => snapshot,
Err(_) => {
return CommandResult::Health(HealthReport {
reachable: false,
url,
status: STATUS_UNREACHABLE.to_string(),
..HealthReport::default()
});
}
};
let (managed_total, managed_pending_decisions) =
match self.client().list_managed_sessions().await {
Ok(sessions) => {
let live = sessions.iter().filter(|s| !s.deleted);
let total = live.clone().count();
let pending = live.filter(|s| s.pending_decision.is_some()).count();
(total, pending)
}
Err(_) => (0, 0),
};
CommandResult::Health(HealthReport {
reachable: true,
url,
status: snapshot.status,
catalog_stale: snapshot.catalog_stale,
catalog_unknown: snapshot.catalog_unknown,
managed_total,
managed_pending_decisions,
})
}
}