Line data Source code
1 : #[cfg(feature = "testing")]
2 : use camino::Utf8PathBuf;
3 : use serde::{Deserialize, Serialize};
4 :
5 0 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
6 : pub enum Root {
7 : V1(V1),
8 : }
9 0 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
10 : pub enum V1 {
11 : InProgress(InProgress),
12 : Done(Done),
13 : }
14 :
15 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
16 : #[serde(transparent)]
17 : pub struct IdempotencyKey(String);
18 :
19 : impl IdempotencyKey {
20 4 : pub fn new(s: String) -> Self {
21 4 : Self(s)
22 4 : }
23 : }
24 :
25 0 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
26 : pub struct InProgress {
27 : pub idempotency_key: IdempotencyKey,
28 : pub location: Location,
29 : pub started_at: chrono::NaiveDateTime,
30 : }
31 :
32 0 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
33 : pub struct Done {
34 : pub idempotency_key: IdempotencyKey,
35 : pub started_at: chrono::NaiveDateTime,
36 : pub finished_at: chrono::NaiveDateTime,
37 : }
38 :
39 0 : #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
40 : pub enum Location {
41 : #[cfg(feature = "testing")]
42 : LocalFs { path: Utf8PathBuf },
43 : AwsS3 {
44 : region: String,
45 : bucket: String,
46 : key: String,
47 : },
48 : }
49 :
50 : impl Root {
51 0 : pub fn is_done(&self) -> bool {
52 0 : match self {
53 0 : Root::V1(v1) => match v1 {
54 0 : V1::Done(_) => true,
55 0 : V1::InProgress(_) => false,
56 : },
57 : }
58 0 : }
59 0 : pub fn idempotency_key(&self) -> &IdempotencyKey {
60 0 : match self {
61 0 : Root::V1(v1) => match v1 {
62 0 : V1::InProgress(in_progress) => &in_progress.idempotency_key,
63 0 : V1::Done(done) => &done.idempotency_key,
64 : },
65 : }
66 0 : }
67 0 : pub fn started_at(&self) -> &chrono::NaiveDateTime {
68 0 : match self {
69 0 : Root::V1(v1) => match v1 {
70 0 : V1::InProgress(in_progress) => &in_progress.started_at,
71 0 : V1::Done(done) => &done.started_at,
72 : },
73 : }
74 0 : }
75 : }
|