1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use ts_rs::TS;
use uuid::Uuid;
/// Status of a task
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
pub enum TaskStatus {
/// Task hasn't started execution yet
Pending,
/// Task is currently being executed
Running,
/// Task has completed successfully
Completed,
/// Task execution failed with an error
Failed,
/// Task is waiting for a manual trigger
AwaitingTrigger,
/// Task is blocked by dependencies
Blocked,
/// Task will not be executed
WontDo,
}
/// Represents a task (runtime instance of a node)
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
pub struct Task {
/// Unique identifier for the task
pub id: Uuid,
/// ID of the workflow run this task belongs to
pub workflow_run_id: Uuid,
/// ID of the node this task is an instance of
pub node_id: String,
/// Current status of the task
pub status: TaskStatus,
/// Whether or not this task is a master task for other matrix tasks.
pub is_master: bool,
/// For matrix tasks, the master task ID
#[serde(default)]
#[ts(optional=nullable)]
pub master_task_id: Option<Uuid>,
/// For matrix tasks, the matrix values
#[serde(default)]
#[ts(optional=nullable)]
pub matrix_values: Option<HashMap<String, serde_json::Value>>,
/// Start time of the task
#[serde(default)]
#[ts(optional=nullable)]
pub started_at: Option<DateTime<Utc>>,
/// End time of the task (if completed or failed)
#[serde(default)]
#[ts(optional=nullable)]
pub ended_at: Option<DateTime<Utc>>,
/// Error message (if failed)
#[serde(default)]
#[ts(optional=nullable)]
pub error: Option<String>,
/// Logs from the task
#[serde(default)]
pub logs: Vec<String>,
}
impl Task {
/// Create a new task
pub fn new(workflow_run_id: Uuid, node_id: String, is_master: bool) -> Self {
Self {
id: Uuid::new_v4(),
workflow_run_id,
node_id,
is_master,
status: TaskStatus::Pending,
master_task_id: None,
matrix_values: None,
started_at: None,
ended_at: None,
error: None,
logs: Vec::new(),
}
}
/// Create a new matrix task
pub fn new_matrix(
workflow_run_id: Uuid,
node_id: String,
master_task_id: Uuid,
matrix_values: HashMap<String, serde_json::Value>,
) -> Self {
Self {
id: Uuid::new_v4(),
workflow_run_id,
node_id,
status: TaskStatus::Pending,
master_task_id: Some(master_task_id),
matrix_values: Some(matrix_values),
started_at: None,
ended_at: None,
error: None,
logs: Vec::new(),
is_master: false,
}
}
}