ya_client_model/activity/
runtime_event.rs

1use crate::activity::{CommandOutput, ExeScriptCommand};
2use chrono::{NaiveDateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
6pub struct RuntimeEvent {
7    pub batch_id: String,
8    pub index: usize,
9    pub timestamp: NaiveDateTime,
10    pub kind: RuntimeEventKind,
11}
12
13impl RuntimeEvent {
14    pub fn new(batch_id: String, index: usize, kind: RuntimeEventKind) -> Self {
15        RuntimeEvent {
16            batch_id,
17            index,
18            kind,
19            timestamp: Utc::now().naive_utc(),
20        }
21    }
22
23    pub fn started(batch_id: String, idx: usize, command: ExeScriptCommand) -> Self {
24        Self::new(batch_id, idx, RuntimeEventKind::Started { command })
25    }
26
27    pub fn finished(
28        batch_id: String,
29        idx: usize,
30        return_code: i32,
31        message: Option<String>,
32    ) -> Self {
33        Self::new(
34            batch_id,
35            idx,
36            RuntimeEventKind::Finished {
37                return_code,
38                message,
39            },
40        )
41    }
42
43    pub fn stdout(batch_id: String, idx: usize, out: CommandOutput) -> Self {
44        Self::new(batch_id, idx, RuntimeEventKind::StdOut(out))
45    }
46
47    pub fn stderr(batch_id: String, idx: usize, out: CommandOutput) -> Self {
48        Self::new(batch_id, idx, RuntimeEventKind::StdErr(out))
49    }
50}
51
52#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
53#[serde(rename_all = "lowercase")]
54pub enum RuntimeEventKind {
55    Started {
56        command: ExeScriptCommand,
57    },
58    Finished {
59        return_code: i32,
60        message: Option<String>,
61    },
62    StdOut(CommandOutput),
63    StdErr(CommandOutput),
64}