Skip to main content

owlauth_types/
health.rs

1use serde::Serialize;
2use utoipa::ToSchema;
3
4/// Minimal response returned by listener liveness and readiness probes.
5#[derive(Clone, Debug, Eq, PartialEq, Serialize, ToSchema)]
6pub struct HealthResponse {
7    /// Stable probe status. Successful probes return `ok`.
8    pub status: String,
9}
10
11impl HealthResponse {
12    /// Creates a successful probe response.
13    #[must_use]
14    pub fn ok() -> Self {
15        Self {
16            status: "ok".to_owned(),
17        }
18    }
19
20    /// Creates a failed readiness response.
21    #[must_use]
22    pub fn unavailable() -> Self {
23        Self {
24            status: "unavailable".to_owned(),
25        }
26    }
27}
28
29#[utoipa::path(
30    get,
31    path = "/health",
32    responses(
33        (status = 200, description = "The listener event loop is responsive", body = HealthResponse)
34    )
35)]
36#[doc(hidden)]
37#[must_use]
38pub fn get_liveness() -> HealthResponse {
39    HealthResponse::ok()
40}
41
42#[utoipa::path(
43    get,
44    path = "/ready",
45    responses(
46        (status = 200, description = "The listener can admit business traffic", body = HealthResponse),
47        (status = 503, description = "A listener-critical dependency is unavailable", body = HealthResponse)
48    )
49)]
50#[doc(hidden)]
51#[must_use]
52pub fn get_readiness() -> HealthResponse {
53    HealthResponse::ok()
54}