use serde::Deserialize;
use crate::client::{API_URL, Client};
#[derive(Debug, Deserialize, Clone)]
struct HealthResponse {
result: ServerHealth,
}
#[derive(Debug, Deserialize, Clone)]
pub struct ServerHealth {
pub worker: ServerHealthStatus,
pub database: ServerHealthStatus,
pub kv: ServerHealthStatus,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ServerHealthStatus {
#[serde(rename = "connected")]
Connected,
#[serde(rename = "disconnected")]
Disconnected,
}
impl Client {
pub async fn server_health(self) -> Result<ServerHealth, crate::ErrorType> {
let url = format!("{API_URL}/health");
let response = self.client.get(url).send().await?;
let response = response.json::<HealthResponse>().await?;
Ok(response.result)
}
}