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 pub fn new(client: &Client) -> Self {
12 let inner = HealthServiceClient::new(client.channel().clone());
13 Self { inner }
14 }
15
16 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 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 pub async fn is_healthy(&self) -> Result<bool> {
34 let status = self.livez().await?;
35 Ok(status == HealthStatus::Pass)
36 }
37}