appletheia_application/outbox/
outbox_state.rs1use super::{
2 OutboxAttemptCount, OutboxLeaseExpiresAt, OutboxNextAttemptAt, OutboxPublishedAt,
3 OutboxRelayInstance,
4};
5
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum OutboxState {
8 Pending {
9 attempt_count: OutboxAttemptCount,
10 next_attempt_after: OutboxNextAttemptAt,
11 },
12 Leased {
13 attempt_count: OutboxAttemptCount,
14 next_attempt_after: OutboxNextAttemptAt,
15 lease_owner: OutboxRelayInstance,
16 lease_until: OutboxLeaseExpiresAt,
17 },
18 Published {
19 published_at: OutboxPublishedAt,
20 attempt_count: OutboxAttemptCount,
21 },
22}
23
24impl OutboxState {
25 pub fn attempt_count(&self) -> OutboxAttemptCount {
26 match self {
27 OutboxState::Pending { attempt_count, .. }
28 | OutboxState::Leased { attempt_count, .. }
29 | OutboxState::Published { attempt_count, .. } => *attempt_count,
30 }
31 }
32
33 pub fn next_attempt_after(&self) -> Option<OutboxNextAttemptAt> {
34 match self {
35 OutboxState::Pending {
36 next_attempt_after, ..
37 }
38 | OutboxState::Leased {
39 next_attempt_after, ..
40 } => Some(*next_attempt_after),
41 OutboxState::Published { .. } => None,
42 }
43 }
44
45 pub fn lease_owner(&self) -> Option<&OutboxRelayInstance> {
46 match self {
47 OutboxState::Leased { lease_owner, .. } => Some(lease_owner),
48 OutboxState::Pending { .. } | OutboxState::Published { .. } => None,
49 }
50 }
51
52 pub fn lease_until(&self) -> Option<OutboxLeaseExpiresAt> {
53 match self {
54 OutboxState::Leased { lease_until, .. } => Some(*lease_until),
55 OutboxState::Pending { .. } | OutboxState::Published { .. } => None,
56 }
57 }
58
59 pub fn published_at(&self) -> Option<OutboxPublishedAt> {
60 match self {
61 OutboxState::Published { published_at, .. } => Some(*published_at),
62 OutboxState::Pending { .. } | OutboxState::Leased { .. } => None,
63 }
64 }
65}