shutdown_tree/shutdown_tree.rs
1//! Demonstrates the four-stage shutdown sequence.
2
3// Import the YAML configuration loader.
4use rust_supervisor::config::loader::load_config_state;
5// Import the supervisor runtime entry point.
6use rust_supervisor::runtime::supervisor::Supervisor;
7// Import shutdown phase names for display.
8use rust_supervisor::shutdown::stage::ShutdownPhase;
9
10// Define the shared example result type.
11type ExampleResult = Result<(), rust_supervisor::error::types::SupervisorError>;
12
13// Use the Tokio runtime for the asynchronous example.
14#[tokio::main]
15// Return typed supervisor errors from the example.
16/// Runs the shutdown tree example.
17async fn main() -> ExampleResult {
18 // Load centralized YAML configuration.
19 let state = load_config_state("examples/config/supervisor.yaml")?;
20 // Derive the supervisor specification from configuration.
21 let spec = state.to_supervisor_spec()?;
22 // Start the supervisor runtime from the specification.
23 let handle = Supervisor::start(spec).await?;
24 // Build the visible shutdown phase list.
25 let phases = [
26 // Show the stop request phase.
27 ShutdownPhase::RequestStop,
28 // Show the graceful drain phase.
29 ShutdownPhase::GracefulDrain,
30 // Show the abort stragglers phase.
31 ShutdownPhase::AbortStragglers,
32 // Show the final reconcile phase.
33 ShutdownPhase::Reconcile,
34 // Finish the shutdown phase list.
35 ];
36 // Iterate over the visible shutdown phases.
37 for phase in phases {
38 // Print each planned phase.
39 println!("planned phase={phase:#?}");
40 // Finish the phase display loop.
41 }
42 // Use the runtime handle for the shutdown request.
43 handle
44 // Request tree shutdown with audit metadata.
45 .shutdown_tree("operator", "shutdown tree example")
46 // Wait for the shutdown command result.
47 .await?;
48 // Finish the example successfully.
49 Ok(())
50 // End the shutdown example.
51}