ora_backend/executions.rs
1//! Executions and related types.
2
3use std::time::SystemTime;
4
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8use crate::{
9 executors::ExecutorId,
10 jobs::{JobId, JobTypeId, RetryPolicy, TimeoutPolicy},
11};
12
13/// An execution ID.
14#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15#[repr(transparent)]
16#[serde(transparent)]
17pub struct ExecutionId(pub Uuid);
18
19impl std::fmt::Display for ExecutionId {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 write!(f, "{}", self.0)
22 }
23}
24
25impl From<Uuid> for ExecutionId {
26 fn from(value: Uuid) -> Self {
27 Self(value)
28 }
29}
30
31impl From<ExecutionId> for Uuid {
32 fn from(value: ExecutionId) -> Self {
33 value.0
34 }
35}
36
37/// Details of an execution.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct ExecutionDetails {
40 /// The execution ID.
41 pub id: ExecutionId,
42 /// The executor ID handling the execution (if any).
43 pub executor_id: Option<ExecutorId>,
44 /// The status of the execution.
45 pub status: ExecutionStatus,
46 /// The timestamp when the execution was created.
47 pub created_at: SystemTime,
48 /// The timestamp when the execution started.
49 pub started_at: Option<SystemTime>,
50 /// The timestamp when the execution successfully completed.
51 pub succeeded_at: Option<SystemTime>,
52 /// The timestamp when the execution failed.
53 pub failed_at: Option<SystemTime>,
54 /// The timestamp when the execution was cancelled.
55 pub cancelled_at: Option<SystemTime>,
56 /// The output or result of the execution.
57 pub output_json: Option<String>,
58 /// The error message if the execution failed or was cancelled.
59 pub failure_reason: Option<String>,
60}
61
62/// The status of an execution.
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
64pub enum ExecutionStatus {
65 /// The execution is pending.
66 Pending,
67 /// The execution is in progress.
68 InProgress,
69 /// The execution has completed successfully.
70 Succeeded,
71 /// The execution has failed.
72 Failed,
73 /// The execution was cancelled.
74 Cancelled,
75}
76
77/// An execution ready to be executed.
78#[derive(Debug, Clone)]
79pub struct ReadyExecution {
80 /// The execution ID.
81 pub execution_id: ExecutionId,
82 /// The job ID.
83 pub job_id: JobId,
84 /// The job type ID of the execution.
85 pub job_type_id: JobTypeId,
86 /// The input JSON for the execution.
87 pub input_payload_json: String,
88 /// The attempt number of the execution.
89 ///
90 /// The first attempt is 1.
91 pub attempt_number: u64,
92 /// The retry policy of the job this execution belongs to.
93 pub retry_policy: RetryPolicy,
94 /// The target execution time for the execution.
95 pub target_execution_time: SystemTime,
96}
97
98/// An execution assigned to an executor.
99pub struct StartedExecution {
100 /// The execution ID.
101 pub execution_id: ExecutionId,
102 /// The executor ID.
103 pub executor_id: ExecutorId,
104 /// The timestamp when the execution started.
105 pub started_at: SystemTime,
106}
107
108/// An execution that was successfully completed.
109pub struct SucceededExecution {
110 /// The execution ID.
111 pub execution_id: ExecutionId,
112 /// The timestamp when the execution completed.
113 pub succeeded_at: SystemTime,
114 /// The output JSON of the execution.
115 pub output_json: String,
116}
117
118/// An execution that has failed.
119pub struct FailedExecution {
120 /// The execution ID.
121 pub execution_id: ExecutionId,
122 /// The job ID.
123 pub job_id: JobId,
124 /// The timestamp when the execution failed.
125 pub failed_at: SystemTime,
126 /// The error message for the failure.
127 pub failure_reason: String,
128}
129
130/// An execution that is currently in progress.
131pub struct InProgressExecution {
132 /// The execution ID.
133 pub execution_id: ExecutionId,
134 /// The job ID.
135 pub job_id: JobId,
136 /// The executor ID handling the execution.
137 pub executor_id: ExecutorId,
138 /// The target execution time for the execution.
139 pub target_execution_time: SystemTime,
140 /// The time the execution was assigned to the executor.
141 pub started_at: SystemTime,
142 /// The timeout policy of the job this execution belongs to.
143 pub timeout_policy: TimeoutPolicy,
144 /// The retry policy of the job this execution belongs to.
145 pub retry_policy: RetryPolicy,
146 /// The attempt number of the execution.
147 ///
148 /// The first attempt is 1.
149 pub attempt_number: u64,
150}