Эта страница ещё не переведена
Ниже показан английский оригинал.
Shutdown
shutdown stops a started service gracefully: hooks, subscriptions, running handlers, then the brokers.
shutdown runs on_shutdown, stops the subscriptions and waits for the handlers still running.
It then shuts the brokers down in reverse order of registration and runs after_shutdown.
The lifecycle page shows the hooks, and shutdown_timeout there bounds the wait for running handlers.
A service that already tore itself down after a fail-fast failure returns that failure from shutdown.
Dropping a RunningApp without shutdown detaches the service with no graceful shutdown.
Example
/// Stops a started service: the shutdown hooks run and the handlers in flight finish first.
async fn stop(running: RunningApp) -> Result<(), Box<dyn Error>> {
let health = running.health();
running.shutdown().await?;
tracing::info!(state = ?health.state(), "stopped");
Ok(())
}