algocline_app/service/
status.rs1use super::AppService;
2
3impl AppService {
4 pub async fn status(&self, session_id: Option<&str>) -> Result<String, String> {
11 let snapshots = self.registry.list_snapshots().await;
12
13 if let Some(sid) = session_id {
15 return match snapshots.get(sid) {
16 Some(snapshot) => {
17 let mut result = snapshot.clone();
18 if let Ok(strategies) = self.session_strategies.lock() {
20 if let Some(name) = strategies.get(sid) {
21 result["strategy"] = serde_json::json!(name);
22 }
23 }
24 result["session_id"] = serde_json::json!(sid);
25 serde_json::to_string_pretty(&result).map_err(|e| e.to_string())
26 }
27 None => Err(format!("session '{sid}' not found (may have completed)")),
28 };
29 }
30
31 if snapshots.is_empty() {
33 return Ok(serde_json::json!({
34 "active_sessions": 0,
35 "sessions": [],
36 })
37 .to_string());
38 }
39
40 let strategies = self.session_strategies.lock().ok();
41 let sessions: Vec<serde_json::Value> = snapshots
42 .into_iter()
43 .map(|(id, mut snapshot)| {
44 if let Some(ref strats) = strategies {
45 if let Some(name) = strats.get(&id) {
46 snapshot["strategy"] = serde_json::json!(name);
47 }
48 }
49 snapshot["session_id"] = serde_json::json!(id);
50 snapshot
51 })
52 .collect();
53
54 let result = serde_json::json!({
55 "active_sessions": sessions.len(),
56 "sessions": sessions,
57 });
58
59 serde_json::to_string_pretty(&result).map_err(|e| e.to_string())
60 }
61}