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.
//! `/metrics` route — Prometheus text-format scrape target.
//!
//! Returns the current contents of the global Prometheus recorder
//! installed at startup by the API binary. The handler is a near-zero-
//! cost call: `PrometheusHandle::render` walks the registered metric
//! sets and emits the text-format representation.
//!
//! Note: this is the *API* metrics endpoint. The worker binary has its
//! own independent endpoint on a separate port (default 9091) so a
//! single Prometheus scrape config can target each process directly.

use axum::extract::State;
use axum::http::{header, HeaderValue};
use axum::response::{IntoResponse, Response};

use crate::api::AppState;

/// `GET /metrics` — Prometheus text format. Content-Type is set to the
/// MIME type Prometheus expects (`text/plain; version=0.0.4`) so
/// scrapers don't fall back to a more expensive negotiation path.
#[utoipa::path(
    get,
    path = "/metrics",
    responses(
        (status = 200, description = "Prometheus text-format metrics", body = String),
    ),
    tag = "ops",
)]
pub async fn metrics(State(state): State<AppState>) -> Response {
    let body = state.metrics.render();
    (
        [(
            header::CONTENT_TYPE,
            HeaderValue::from_static("text/plain; version=0.0.4"),
        )],
        body,
    )
        .into_response()
}