use crate::{client::Client, error::Result};
use ev_types::v1::{health_service_client::HealthServiceClient, GetHealthResponse, HealthStatus};
use tonic::Request;
pub struct HealthClient {
inner: HealthServiceClient<tonic::transport::Channel>,
}
impl HealthClient {
pub fn new(client: &Client) -> Self {
let inner = HealthServiceClient::new(client.channel().clone());
Self { inner }
}
pub async fn livez(&self) -> Result<HealthStatus> {
let request = Request::new(());
let response = self.inner.clone().livez(request).await?;
Ok(response.into_inner().status())
}
pub async fn get_health(&self) -> Result<GetHealthResponse> {
let request = Request::new(());
let response = self.inner.clone().livez(request).await?;
Ok(response.into_inner())
}
pub async fn is_healthy(&self) -> Result<bool> {
let status = self.livez().await?;
Ok(status == HealthStatus::Pass)
}
}