obscura-server 0.3.9

A server for relaying secure messages using the Signal Protocol
Documentation
use crate::api::MgmtState;
use axum::{Json, extract::State, http::StatusCode, response::IntoResponse};
use serde_json::json;

/// Liveness probe: returns 200 OK as long as the server is running.
pub async fn livez() -> impl IntoResponse {
    StatusCode::OK
}

/// Readiness probe: checks connectivity to the database and S3.
pub async fn readyz(State(state): State<MgmtState>) -> impl IntoResponse {
    let (db_res, storage_res) = tokio::join!(
        state.health_service.check_db(),
        state.health_service.check_storage()
    );

    let mut status_code = StatusCode::OK;
    let db_status = if let Err(e) = db_res {
        tracing::warn!(error = %e, component = "database", "Readiness probe failed");
        status_code = StatusCode::SERVICE_UNAVAILABLE;
        "error"
    } else {
        "ok"
    };

    let storage_status = if let Err(e) = storage_res {
        tracing::warn!(error = %e, component = "storage", "Readiness probe failed");
        status_code = StatusCode::SERVICE_UNAVAILABLE;
        "error"
    } else {
        "ok"
    };

    (
        status_code,
        Json(json!({
            "status": if status_code == StatusCode::OK { "ok" } else { "error" },
            "database": db_status,
            "storage": storage_status,
        })),
    )
}