agentmux_launcher/
startup_events.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum StartupStatus {
17 Ok,
18 Warn,
19 Error,
20}
21
22#[derive(Debug)]
23pub enum StartupEvent {
24 StageBegin {
26 stage: &'static str,
27 label: &'static str,
28 },
29 StageEnd {
31 stage: &'static str,
32 duration_ms: u64,
33 status: StartupStatus,
34 detail: Option<String>,
35 },
36 SubBegin {
38 stage: &'static str,
39 id: String,
40 label: String,
41 },
42 SubEnd {
44 stage: &'static str,
45 id: String,
46 duration_ms: u64,
47 status: StartupStatus,
48 detail: Option<String>,
50 },
51}
52
53#[derive(Clone, Debug)]
55pub struct StartupEventSink {
56 tx: std::sync::mpsc::Sender<StartupEvent>,
57}
58
59impl StartupEventSink {
60 pub fn new() -> (Self, std::sync::mpsc::Receiver<StartupEvent>) {
63 let (tx, rx) = std::sync::mpsc::channel();
64 (Self { tx }, rx)
65 }
66
67 pub fn stage_begin(&self, stage: &'static str, label: &'static str) {
68 let _ = self.tx.send(StartupEvent::StageBegin { stage, label });
69 }
70
71 pub fn stage_end(
72 &self,
73 stage: &'static str,
74 duration_ms: u64,
75 status: StartupStatus,
76 detail: Option<String>,
77 ) {
78 let _ = self.tx.send(StartupEvent::StageEnd {
79 stage,
80 duration_ms,
81 status,
82 detail,
83 });
84 }
85
86 pub fn sub_begin(
87 &self,
88 stage: &'static str,
89 id: impl Into<String>,
90 label: impl Into<String>,
91 ) {
92 let _ = self.tx.send(StartupEvent::SubBegin {
93 stage,
94 id: id.into(),
95 label: label.into(),
96 });
97 }
98
99 pub fn sub_end(
100 &self,
101 stage: &'static str,
102 id: impl Into<String>,
103 duration_ms: u64,
104 status: StartupStatus,
105 detail: Option<String>,
106 ) {
107 let _ = self.tx.send(StartupEvent::SubEnd {
108 stage,
109 id: id.into(),
110 duration_ms,
111 status,
112 detail,
113 });
114 }
115}