1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum RunStatus {
10 #[default]
12 Running,
13 Success,
15 Failed,
17 Canceled,
19 Timeout,
23}
24
25impl std::fmt::Display for RunStatus {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::Running => write!(f, "running"),
29 Self::Success => write!(f, "success"),
30 Self::Failed => write!(f, "failed"),
31 Self::Canceled => write!(f, "canceled"),
32 Self::Timeout => write!(f, "timeout"),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct Run {
40 pub run_id: String,
42 pub job_id: String,
44 pub task_name: String,
46 pub attempt: i32,
48 pub status: RunStatus,
50 pub started_at: DateTime<Utc>,
52 pub finished_at: Option<DateTime<Utc>>,
54 pub duration_ms: Option<i64>,
56 pub error_message: Option<String>,
58}
59
60impl Run {
61 #[must_use]
63 pub fn new(job_id: &str, task_name: &str, attempt: i32) -> Self {
64 Self {
65 run_id: uuid::Uuid::new_v4().to_string(),
66 job_id: job_id.to_string(),
67 task_name: task_name.to_string(),
68 attempt,
69 status: RunStatus::Running,
70 started_at: Utc::now(),
71 finished_at: None,
72 duration_ms: None,
73 error_message: None,
74 }
75 }
76}