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 /// The target execution time for the execution.
61 ///
62 /// This might differ from the job's target execution time
63 /// if the execution was created as a retry of a failed execution.
64 pub target_execution_time: SystemTime,
65}
66
67/// The status of an execution.
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
69pub enum ExecutionStatus {
70 /// The execution is pending.
71 Pending,
72 /// The execution is in progress.
73 InProgress,
74 /// The execution has completed successfully.
75 Succeeded,
76 /// The execution has failed.
77 Failed,
78 /// The execution was cancelled.
79 Cancelled,
80}
81
82/// An execution ready to be executed.
83#[derive(Debug, Clone)]
84pub struct ReadyExecution {
85 /// The execution ID.
86 pub execution_id: ExecutionId,
87 /// The job ID.
88 pub job_id: JobId,
89 /// The job type ID of the execution.
90 pub job_type_id: JobTypeId,
91 /// The input JSON for the execution.
92 pub input_payload_json: String,
93 /// The attempt number of the execution.
94 ///
95 /// The first attempt is 1.
96 pub attempt_number: u64,
97 /// The retry policy of the job this execution belongs to.
98 pub retry_policy: RetryPolicy,
99 /// The target execution time for the execution.
100 pub target_execution_time: SystemTime,
101}
102
103/// An execution assigned to an executor.
104pub struct StartedExecution {
105 /// The execution ID.
106 pub execution_id: ExecutionId,
107 /// The executor ID.
108 pub executor_id: ExecutorId,
109 /// The timestamp when the execution started.
110 pub started_at: SystemTime,
111}
112
113/// An execution that was successfully completed.
114pub struct SucceededExecution {
115 /// The execution ID.
116 pub execution_id: ExecutionId,
117 /// The timestamp when the execution completed.
118 pub succeeded_at: SystemTime,
119 /// The output JSON of the execution.
120 pub output_json: String,
121}
122
123/// An execution that has failed.
124pub struct FailedExecution {
125 /// The execution ID.
126 pub execution_id: ExecutionId,
127 /// The job ID.
128 pub job_id: JobId,
129 /// The timestamp when the execution failed.
130 pub failed_at: SystemTime,
131 /// The error message for the failure.
132 pub failure_reason: String,
133}
134
135/// A failed execution that needs to be retried.
136pub struct RetriedExecution {
137 /// The failed execution.
138 pub failed_execution: FailedExecution,
139 /// The target execution time for the retry.
140 pub retry_execution_time: SystemTime,
141}
142
143/// An execution that is currently in progress.
144pub struct InProgressExecution {
145 /// The execution ID.
146 pub execution_id: ExecutionId,
147 /// The job ID.
148 pub job_id: JobId,
149 /// The executor ID handling the execution.
150 pub executor_id: ExecutorId,
151 /// The target execution time for the execution.
152 pub target_execution_time: SystemTime,
153 /// The time the execution was assigned to the executor.
154 pub started_at: SystemTime,
155 /// The timeout policy of the job this execution belongs to.
156 pub timeout_policy: TimeoutPolicy,
157 /// The retry policy of the job this execution belongs to.
158 pub retry_policy: RetryPolicy,
159 /// The attempt number of the execution.
160 ///
161 /// The first attempt is 1.
162 pub attempt_number: u64,
163}