ev_client/
health.rs

1use crate::{client::Client, error::Result};
2use ev_types::v1::{health_service_client::HealthServiceClient, GetHealthResponse, HealthStatus};
3use tonic::Request;
4
5pub struct HealthClient {
6    inner: HealthServiceClient<tonic::transport::Channel>,
7}
8
9impl HealthClient {
10    /// Create a new HealthClient from a Client
11    pub fn new(client: &Client) -> Self {
12        let inner = HealthServiceClient::new(client.channel().clone());
13        Self { inner }
14    }
15
16    /// Check if the node is alive and get its health status
17    pub async fn livez(&self) -> Result<HealthStatus> {
18        let request = Request::new(());
19        let response = self.inner.clone().livez(request).await?;
20
21        Ok(response.into_inner().status())
22    }
23
24    /// Get the full health response
25    pub async fn get_health(&self) -> Result<GetHealthResponse> {
26        let request = Request::new(());
27        let response = self.inner.clone().livez(request).await?;
28
29        Ok(response.into_inner())
30    }
31
32    /// Check if the node is healthy (status is PASS)
33    pub async fn is_healthy(&self) -> Result<bool> {
34        let status = self.livez().await?;
35        Ok(status == HealthStatus::Pass)
36    }
37}