Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Binary/Shutdown/
SchedulerShutdown.rs

1//! # Scheduler Shutdown Module
2//!
3//! Handles graceful shutdown of the Echo task scheduler.
4
5use std::sync::Arc;
6
7use Echo::Scheduler::Scheduler::Scheduler;
8
9use crate::dev_log;
10
11/// Stops the Echo task scheduler and cleans up its resources.
12///
13/// # Arguments
14///
15/// * `SchedulerForShutdown` - Arc-wrapped scheduler to shut down
16///
17/// # Returns
18///
19/// A `Result` indicating success or failure.
20///
21/// # Shutdown Process
22///
23/// This function performs:
24/// - Stops accepting new tasks
25/// - Completes in-progress tasks
26/// - Cleans up scheduler resources
27///
28/// # Errors
29///
30/// Returns an error if the scheduler is not exclusively owned or stop fails.
31pub async fn SchedulerShutdown(SchedulerForShutdown:Arc<Scheduler>) -> Result<(), String> {
32	dev_log!("lifecycle", "[Shutdown] [Scheduler] Stopping Echo scheduler...");
33
34	// Try to get exclusive ownership for shutdown
35	match Arc::try_unwrap(SchedulerForShutdown) {
36		Ok(mut Scheduler) => {
37			Scheduler.Stop().await;
38
39			dev_log!("lifecycle", "[Shutdown] [Scheduler] Echo scheduler stopped successfully.");
40
41			Ok(())
42		},
43
44		Err(_) => Err("Scheduler not exclusively owned".to_string()),
45	}
46}