-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask.rs
More file actions
290 lines (272 loc) · 7.67 KB
/
task.rs
File metadata and controls
290 lines (272 loc) · 7.67 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use strum::{AsRefStr, EnumString};
use time::OffsetDateTime;
use url::Url;
use crate::Hateoas;
#[cfg(feature = "serde")]
use super::utils;
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "SCREAMING_SNAKE_CASE")
)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsRefStr, EnumString)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[non_exhaustive]
pub enum TaskStatusType {
Received,
Pending,
Scheduled,
Rejected,
Denied,
MovedVis,
Bumped,
Moved,
Cancelled,
SystemError,
QueuedPass,
Configured,
Downlinking,
Recording,
CompletedPass,
DataCloud,
Processing,
ReadyCustom,
ProcessedCustom,
ErrorCustom,
Completed,
CompletedError,
PushedToCustomer,
ErrorPushToCustomer,
Invoiced,
Paid,
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TaskStatus {
#[cfg_attr(feature = "serde", serde(with = "crate::utils::timestamp"))]
pub created: OffsetDateTime,
pub status: TaskStatusType,
pub reason: String,
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "SCREAMING_SNAKE_CASE")
)]
#[derive(
Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsRefStr, EnumString,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[non_exhaustive]
pub enum Polarization {
#[default]
Right,
Left,
Vertical,
Horizontal,
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "SCREAMING_SNAKE_CASE")
)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsRefStr, EnumString)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[non_exhaustive]
pub enum TaskType {
Before,
After,
Test,
Around,
Exact,
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Task {
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub created: OffsetDateTime,
#[cfg_attr(
feature = "serde",
serde(default, with = "time::serde::iso8601::option")
)]
pub modified: Option<OffsetDateTime>,
pub found_visibility: bool,
/// Unavailable for user accounts
#[cfg_attr(feature = "serde", serde(default))]
pub internal_meta_data: Option<HashMap<String, String>>,
/// Unavailable for user accounts
#[cfg_attr(feature = "serde", serde(default))]
pub score: Option<u8>,
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub start: OffsetDateTime,
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub end: OffsetDateTime,
#[cfg_attr(
feature = "serde",
serde(default, with = "time::serde::iso8601::option")
)]
pub visibility_start: Option<OffsetDateTime>,
#[cfg_attr(
feature = "serde",
serde(default, with = "time::serde::iso8601::option")
)]
pub visibility_end: Option<OffsetDateTime>,
pub billable: bool,
pub duration_in_seconds: u32,
pub task_within_config_window: bool,
pub duration: String,
pub file_results: Vec<String>,
#[cfg_attr(feature = "serde", serde(default))]
pub meta_data: Option<HashMap<String, String>>,
#[cfg_attr(
feature = "serde",
serde(rename = "_links", with = "utils::links::serde", default)
)]
pub links: HashMap<String, Url>,
}
impl Hateoas for Task {
fn get_links(&self) -> &HashMap<String, url::Url> {
&self.links
}
fn get_links_mut(&mut self) -> &mut HashMap<String, url::Url> {
&mut self.links
}
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TaskStatusEvent {
pub task_request_id: i32,
pub task_request_uri: String,
pub status_changes: Vec<TaskStatus>,
}
impl TaskStatusEvent {
pub fn latest_status(&self) -> Option<&TaskStatus> {
self.status_changes
.iter()
.max_by_key(|status| status.created)
}
}
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TaskRequest {
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub created: OffsetDateTime,
#[cfg_attr(
feature = "serde",
serde(default, with = "time::serde::iso8601::option")
)]
pub modified: Option<OffsetDateTime>,
/// Unavailable for user accounts
#[cfg_attr(feature = "serde", serde(default))]
pub internal_meta_data: Option<HashMap<String, String>>,
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub task_type: TaskType,
#[cfg_attr(feature = "serde", serde(default))]
pub hours_of_flex: u32,
pub duration: u32,
pub minimum_duration: u32,
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub target_date: OffsetDateTime,
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub earliest_start: OffsetDateTime,
#[cfg_attr(feature = "serde", serde(with = "time::serde::iso8601"))]
pub latest_start: OffsetDateTime,
pub transmitting: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub test_file: Option<String>,
pub status_changes: Vec<TaskStatus>,
pub task_active: bool,
pub task_request_scheduled: bool,
pub task_request_cancelled: bool,
pub flex: bool,
pub latest_status_change: TaskStatus,
#[cfg_attr(feature = "serde", serde(default))]
pub meta_data: Option<HashMap<String, String>>,
#[cfg_attr(
feature = "serde",
serde(rename = "_links", with = "utils::links::serde", default)
)]
pub links: HashMap<String, Url>,
}
impl Hateoas for TaskRequest {
fn get_links(&self) -> &HashMap<String, url::Url> {
&self.links
}
fn get_links_mut(&mut self) -> &mut HashMap<String, url::Url> {
&mut self.links
}
}
#[cfg(all(test, feature = "serde"))]
mod tests {
use super::*;
#[test]
fn task_status_event() {
let json = r#"
{
"taskRequestId": 189348,
"taskRequestUri": "https://test-api.atlasground.com/api/requests/189348",
"statusChanges": [
{
"created": "2025-08-01T19:55:07.061Z",
"status": "RECEIVED",
"reason": "Saved to Database and awaiting scheduling"
},
{
"created": "2025-08-01T19:55:07.674Z",
"status": "SCHEDULED",
"reason": "Test Task Scheduled"
},
{
"created": "2025-08-01T19:55:08.986Z",
"status": "QUEUED_PASS",
"reason": "Pass has been queued to execute"
}
]
}"#;
let event: TaskStatusEvent = serde_json::from_str(json).unwrap();
assert_eq!(
event.latest_status().unwrap().status,
TaskStatusType::QueuedPass
);
}
#[test]
fn task_status_event_float_timestamp() {
use time::macros::datetime;
let json = r#"
{
"taskRequestId": 190029,
"taskRequestUri": "https://test-api.atlasground.com/api/requests/190029",
"statusChanges": [
{
"created": 1754409946.362000000,
"status": "RECEIVED",
"reason": "Saved to Database and awaiting scheduling"
}
]
}"#;
let event: TaskStatusEvent = serde_json::from_str(json).unwrap();
assert_eq!(
datetime!(2025 - 08 - 05 16:05:46.361_999_989).assume_utc(),
event.status_changes[0].created
);
}
}