Mountain/RunTime/Shutdown/
ShutdownWithRecovery.rs1#![allow(non_snake_case)]
2
3use CommonLibrary::Error::CommonError::CommonError;
8
9use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
10
11impl ApplicationRunTime {
12 pub async fn ShutdownWithRecovery(&self) -> Result<(), CommonError> {
13 dev_log!("lifecycle", "[ApplicationRunTime] Initiating robust shutdown with recovery...");
14
15 let mut ShutdownErrors:Vec<String> = Vec::new();
16
17 match self.ShutdownCocoonWithRetry().await {
18 Ok(()) => dev_log!("lifecycle", "[ApplicationRunTime] Cocoon shutdown successful"),
19
20 Err(Error) => {
21 ShutdownErrors.push(format!("Cocoon shutdown failed: {}", Error));
22
23 dev_log!("lifecycle", "warn: [ApplicationRunTime] Cocoon shutdown failed, continuing...");
24 },
25 }
26
27 match self.DisposeTerminalsSafely().await {
28 Ok(()) => dev_log!("lifecycle", "[ApplicationRunTime] Terminal disposal successful"),
29
30 Err(Error) => {
31 ShutdownErrors.push(format!("Terminal disposal failed: {}", Error));
32
33 dev_log!(
34 "lifecycle",
35 "warn: [ApplicationRunTime] Terminal disposal failed, continuing..."
36 );
37 },
38 }
39
40 match self.SaveApplicationState().await {
41 Ok(()) => dev_log!("lifecycle", "[ApplicationRunTime] Application state saved"),
42
43 Err(Error) => {
44 ShutdownErrors.push(format!("State save failed: {}", Error));
45
46 dev_log!(
47 "lifecycle",
48 "warn: [ApplicationRunTime] Failed to save application state, continuing..."
49 );
50 },
51 }
52
53 self.FlushPendingOperations().await;
54
55 if !ShutdownErrors.is_empty() {
56 Err(CommonError::Unknown {
57 Description:format!("Shutdown completed with {} errors: {:?}", ShutdownErrors.len(), ShutdownErrors),
58 })
59 } else {
60 Ok(())
61 }
62 }
63}