Skip to main content

Module maintenance

Module maintenance 

Source
Expand description

Maintenance-mode middleware — return 503 with Retry-After from a shared atomic flag, so an orchestrator can drain traffic before a deploy / migration without killing in-flight requests. See maintenance::MaintenanceFlag + maintenance::MaintenanceLayer. Maintenance-mode middleware — return 503 with Retry-After from a shared flag, so an orchestrator (or a sidecar) can drain traffic before a deploy / migration without killing in-flight requests.

§Quick start

use rustango::maintenance::{MaintenanceFlag, MaintenanceLayer, MaintenanceRouterExt};
use std::time::Duration;

let flag = MaintenanceFlag::new();

let app = axum::Router::new()
    .route("/api/posts", axum::routing::get(list))
    .maintenance(MaintenanceLayer::new(flag.clone())
        .retry_after(Duration::from_secs(30))
        .allow_path("/health")
        .allow_path("/ready"));

// Some other place (signal handler, control-plane endpoint, ...):
flag.enable();   // start serving 503
flag.disable();  // resume normal operation

§What it does

  • When the flag is OFF, requests pass through unchanged.
  • When the flag is ON, requests return 503 Service Unavailable with a configurable JSON body, Retry-After, and the standard Cache-Control: no-store so caches don’t sticky the maintenance page.
  • Optional allow-list of exact paths that bypass the layer (almost always /health and /ready so orchestrators keep getting truth while you’re under maintenance).

Pair this with crate::body_limit::BodyLimitLayer and crate::real_ip::RealIpLayer in the same router stack — order doesn’t matter much, but putting maintenance OUTERMOST means a flipped flag short-circuits before any handler work runs.

Structs§

MaintenanceFlag
Shared on/off flag. Cheap to clone; threadsafe.
MaintenanceLayer
Maintenance-mode middleware configuration. Cheap to clone.

Traits§

MaintenanceRouterExt