Skip to main content

demo/
runner.rs

1//! Orchestrates the modular supervisor demo process.
2
3// Import the demo runtime starter.
4use crate::bootstrap::start_demo_dashboard_runtime;
5// Import startup summary output.
6use crate::output::print_startup_summary;
7// Import graceful shutdown helper.
8use crate::shutdown::shutdown_demo;
9// Import configuration loading.
10use rust_supervisor::config::loader::load_config_state;
11// Import validated configuration state.
12use rust_supervisor::config::state::ConfigState;
13// Import the supervisor runtime entry point.
14use rust_supervisor::runtime::supervisor::Supervisor;
15// Import path storage.
16use std::path::PathBuf;
17
18/// Runs the demo process.
19///
20/// # Arguments
21///
22/// - `config_path`: Supervisor configuration file path.
23///
24/// # Returns
25///
26/// Returns success after operator shutdown.
27pub(crate) async fn run_demo(
28    // Continue the demo expression.
29    config_path: PathBuf,
30    // Continue the demo expression.
31) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
32    // Load the full demo configuration.
33    let state = load_config_state(&config_path)?;
34    // Start the demo-owned dashboard IPC and registration runtime.
35    let demo_runtime = start_demo_dashboard_runtime(&state)?;
36    // Build a pure supervisor runtime configuration.
37    let supervisor_state = supervisor_runtime_state(state);
38    // Start the library supervisor without core demo state intrusion.
39    let handle = Supervisor::start_from_config_state(supervisor_state).await?;
40    // Query current state once to prove the runtime is live.
41    let current = handle.current_state().await?;
42    // Print the runtime state for operator inspection.
43    println!("{current:#?}");
44    // Print the demo startup summary.
45    print_startup_summary(&config_path, demo_runtime.as_ref());
46    // Wait until the operator stops the demo process.
47    tokio::signal::ctrl_c().await?;
48    // Shut down the supervisor tree before dropping resources.
49    shutdown_demo(&handle).await?;
50    // Drop the supervisor handle explicitly.
51    drop(handle);
52    // Drop the demo runtime explicitly so the IPC socket is cleaned up.
53    drop(demo_runtime);
54    // Finish the demo successfully.
55    Ok(())
56    // End demo runner.
57}
58
59/// Removes IPC from the library supervisor runtime state.
60///
61/// # Arguments
62///
63/// - `state`: Full loaded configuration state.
64///
65/// # Returns
66///
67/// Returns a configuration state for the pure library supervisor runtime.
68fn supervisor_runtime_state(mut state: ConfigState) -> ConfigState {
69    // Keep dashboard IPC owned by the demo runtime instead of core runtime.
70    state.ipc = None;
71    // Return the adjusted runtime state.
72    state
73    // End runtime state adjustment.
74}