butterflow_models/
task.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use ts_rs::TS;
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
9pub enum TaskStatus {
10 Pending,
12
13 Running,
15
16 Completed,
18
19 Failed,
21
22 AwaitingTrigger,
24
25 Blocked,
27
28 WontDo,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, TS)]
34pub struct Task {
35 pub id: Uuid,
37
38 pub workflow_run_id: Uuid,
40
41 pub node_id: String,
43
44 pub status: TaskStatus,
46
47 pub is_master: bool,
49
50 #[serde(default)]
52 #[ts(optional=nullable)]
53 pub master_task_id: Option<Uuid>,
54
55 #[serde(default)]
57 #[ts(optional=nullable)]
58 pub matrix_values: Option<HashMap<String, serde_json::Value>>,
59
60 #[serde(default)]
62 #[ts(optional=nullable)]
63 pub started_at: Option<DateTime<Utc>>,
64
65 #[serde(default)]
67 #[ts(optional=nullable)]
68 pub ended_at: Option<DateTime<Utc>>,
69
70 #[serde(default)]
72 #[ts(optional=nullable)]
73 pub error: Option<String>,
74
75 #[serde(default)]
77 pub logs: Vec<String>,
78}
79
80impl Task {
81 pub fn new(workflow_run_id: Uuid, node_id: String, is_master: bool) -> Self {
83 Self {
84 id: Uuid::new_v4(),
85 workflow_run_id,
86 node_id,
87 is_master,
88 status: TaskStatus::Pending,
89 master_task_id: None,
90 matrix_values: None,
91 started_at: None,
92 ended_at: None,
93 error: None,
94 logs: Vec::new(),
95 }
96 }
97
98 pub fn new_matrix(
100 workflow_run_id: Uuid,
101 node_id: String,
102 master_task_id: Uuid,
103 matrix_values: HashMap<String, serde_json::Value>,
104 ) -> Self {
105 Self {
106 id: Uuid::new_v4(),
107 workflow_run_id,
108 node_id,
109 status: TaskStatus::Pending,
110 master_task_id: Some(master_task_id),
111 matrix_values: Some(matrix_values),
112 started_at: None,
113 ended_at: None,
114 error: None,
115 logs: Vec::new(),
116 is_master: false,
117 }
118 }
119}