seiva-server 0.1.0

Delonix Seiva — the service runtime: mounts the facade-driven HTTP app, runs a worker host, reads 12-factor config, shuts down gracefully. DORM-free.
Documentation
//! The `seiva-server` binary: a thin `main` over the [`seiva_server`] library.
//!
//! It reads [`ServerConfig`] from the environment, installs a shutdown signal
//! (Ctrl-C, and `SIGTERM` on unix), and runs the HTTP server ([`serve`]) and the
//! background worker host ([`run_workers`]) concurrently, sharing the shutdown.
//! On a configuration error it prints every problem and exits non-zero; on a
//! serve error it reports it and exits non-zero.

#![forbid(unsafe_code)]

use std::process::ExitCode;

use seiva_server::{observability, run_workers, serve, shutdown_signal, ServerConfig};

#[tokio::main(flavor = "multi_thread")]
async fn main() -> ExitCode {
    // Structured JSON logs to stdout before anything else, so even a config error
    // is one parseable line for the platform to collect.
    observability::init();

    let config = match ServerConfig::from_process_env() {
        Ok(config) => config,
        Err(error) => {
            tracing::error!(%error, "invalid configuration");
            return ExitCode::FAILURE;
        }
    };

    tracing::info!(env = %config.env, http = %config.http_addr, "starting");

    // Serve and the worker host run concurrently, each with its own shutdown
    // future over the same OS signals.
    let (served, reports) = tokio::join!(
        serve(config, shutdown_signal()),
        run_workers(shutdown_signal())
    );

    for report in &reports {
        tracing::info!(
            passes = report.passes,
            processed = report.processed,
            errors = report.errors,
            "worker stopped"
        );
    }

    match served {
        Ok(()) => {
            tracing::info!("stopped cleanly");
            ExitCode::SUCCESS
        }
        Err(error) => {
            tracing::error!(%error, "serve failed");
            ExitCode::FAILURE
        }
    }
}