rust-job-queue-api-worker-system 0.1.0

A production-shaped Rust job queue: Axum API + async workers + Postgres SKIP LOCKED dequeue, retries with decorrelated jitter, idempotency, cooperative cancellation, OpenAPI, Prometheus metrics.
//! `/health` route — liveness check.
//!
//! The check is "can we round-trip a no-op query to Postgres?" rather
//! than just "is this process up?". A process that can't reach its
//! database is not actually healthy from a consumer's perspective, so
//! the latter would be a false-positive signal.

use axum::extract::State;
use axum::Json;
use sqlx::query::query;

use crate::api::dto::HealthResponse;
use crate::api::error::ApiError;
use crate::api::AppState;

/// `GET /health` — return 200 with `{"status":"ok"}` if Postgres is
/// reachable, 500 otherwise.
#[utoipa::path(
    get,
    path = "/health",
    responses(
        (status = 200, description = "Service and database are reachable", body = HealthResponse),
        (status = 500, description = "Database not reachable", body = crate::api::dto::ErrorBody),
    ),
    tag = "ops",
)]
pub async fn health(State(state): State<AppState>) -> Result<Json<HealthResponse>, ApiError> {
    // `SELECT 1` is the standard liveness probe: it forces a real
    // round-trip without touching application data. The `?` propagates
    // any sqlx::Error into `ApiError::Internal` via the `From` impl in
    // `api/error.rs`.
    query("SELECT 1").execute(&state.pool).await?;
    Ok(Json(HealthResponse { status: "ok" }))
}