ryuk 0.1.1

A Laravel-style full-stack web framework for Rust: axum, SeaORM and Inertia, with auth, queues, mail, storage, cache, scheduling and an MCP server.
Documentation
//! `/healthz` (liveness) and `/readyz` (readiness) endpoints.
use axum::{Json, Router, extract::State, http::StatusCode, response::IntoResponse, routing::get};
use serde_json::json;
use std::{future::Future, pin::Pin, sync::Arc};

/// Boxed future returned by readiness checks.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

/// A readiness check: `Err(reason)` marks the app not ready.
pub type Check = Arc<dyn Fn() -> BoxFuture<'static, Result<(), String>> + Send + Sync>;

/// `GET /healthz` always 200; `GET /readyz` is 200 only when every check passes.
pub(crate) fn router(checks: Vec<(String, Check)>) -> Router {
    Router::new()
        .route("/healthz", get(|| async { "ok" }))
        .route("/readyz", get(ready))
        .with_state(Arc::new(checks))
}

async fn ready(State(checks): State<Arc<Vec<(String, Check)>>>) -> impl IntoResponse {
    let mut failed = vec![];
    for (name, check) in checks.iter() {
        if let Err(e) = check().await {
            tracing::warn!(check = %name, "readiness check failed: {e}");
            failed.push(name.as_str());
        }
    }
    if failed.is_empty() {
        (StatusCode::OK, Json(json!({"status": "ok"})))
    } else {
        (
            StatusCode::SERVICE_UNAVAILABLE,
            Json(json!({"status": "unavailable", "failed": failed})),
        )
    }
}