Skip to main content

steamroom_cli/daemon/proto/
event.rs

1use super::JobId;
2use super::JobKind;
3use super::LogLevel;
4use super::ProgressUpdate;
5use super::status::StatusSnapshot;
6use rkyv::Archive;
7use rkyv::Deserialize;
8use rkyv::Serialize;
9
10#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
11#[rkyv(derive(Debug))]
12pub enum Event {
13    JobStarted {
14        job_id: JobId,
15        kind: JobKind,
16        args_summary: String,
17    },
18    JobFinished {
19        job_id: JobId,
20        exit_code: i32,
21    },
22    Log {
23        job_id: Option<JobId>,
24        level: LogLevel,
25        target: String,
26        message: String,
27    },
28    Progress {
29        job_id: JobId,
30        update: ProgressUpdate,
31    },
32    Stdout {
33        job_id: JobId,
34        line: String,
35    },
36    QueueChanged {
37        snapshot: StatusSnapshot,
38    },
39}
40
41impl Event {
42    /// `Some(job_id)` for events scoped to a specific job, `None` for
43    /// daemon-wide events (`Log { job_id: None, .. }`, `QueueChanged`).
44    pub fn job_id(&self) -> Option<JobId> {
45        match self {
46            Event::JobStarted { job_id, .. }
47            | Event::JobFinished { job_id, .. }
48            | Event::Progress { job_id, .. }
49            | Event::Stdout { job_id, .. } => Some(*job_id),
50            Event::Log { job_id, .. } => *job_id,
51            Event::QueueChanged { .. } => None,
52        }
53    }
54}