tirea_contract/storage/
mailbox_traits.rs1use async_trait::async_trait;
2
3use super::{
4 MailboxEntry, MailboxInterrupt, MailboxPage, MailboxQuery, MailboxState, MailboxStoreError,
5};
6
7#[async_trait]
8pub trait MailboxReader: Send + Sync {
9 async fn load_mailbox_entry(
10 &self,
11 entry_id: &str,
12 ) -> Result<Option<MailboxEntry>, MailboxStoreError>;
13
14 async fn load_mailbox_state(
15 &self,
16 mailbox_id: &str,
17 ) -> Result<Option<MailboxState>, MailboxStoreError>;
18
19 async fn list_mailbox_entries(
20 &self,
21 query: &MailboxQuery,
22 ) -> Result<MailboxPage, MailboxStoreError>;
23}
24
25#[async_trait]
26pub trait MailboxWriter: MailboxReader {
27 async fn enqueue_mailbox_entry(&self, entry: &MailboxEntry) -> Result<(), MailboxStoreError>;
28
29 async fn ensure_mailbox_state(
30 &self,
31 mailbox_id: &str,
32 now: u64,
33 ) -> Result<MailboxState, MailboxStoreError>;
34
35 async fn claim_mailbox_entries(
36 &self,
37 mailbox_id: Option<&str>,
38 limit: usize,
39 consumer_id: &str,
40 now: u64,
41 lease_duration_ms: u64,
42 ) -> Result<Vec<MailboxEntry>, MailboxStoreError>;
43
44 async fn claim_mailbox_entry(
45 &self,
46 entry_id: &str,
47 consumer_id: &str,
48 now: u64,
49 lease_duration_ms: u64,
50 ) -> Result<Option<MailboxEntry>, MailboxStoreError>;
51
52 async fn ack_mailbox_entry(
53 &self,
54 entry_id: &str,
55 claim_token: &str,
56 now: u64,
57 ) -> Result<(), MailboxStoreError>;
58
59 async fn nack_mailbox_entry(
60 &self,
61 entry_id: &str,
62 claim_token: &str,
63 retry_at: u64,
64 error: &str,
65 now: u64,
66 ) -> Result<(), MailboxStoreError>;
67
68 async fn dead_letter_mailbox_entry(
69 &self,
70 entry_id: &str,
71 claim_token: &str,
72 error: &str,
73 now: u64,
74 ) -> Result<(), MailboxStoreError>;
75
76 async fn cancel_mailbox_entry(
77 &self,
78 entry_id: &str,
79 now: u64,
80 ) -> Result<Option<MailboxEntry>, MailboxStoreError>;
81
82 async fn supersede_mailbox_entry(
83 &self,
84 entry_id: &str,
85 now: u64,
86 reason: &str,
87 ) -> Result<Option<MailboxEntry>, MailboxStoreError>;
88
89 async fn cancel_pending_for_mailbox(
90 &self,
91 mailbox_id: &str,
92 now: u64,
93 exclude_entry_id: Option<&str>,
94 ) -> Result<Vec<MailboxEntry>, MailboxStoreError>;
95
96 async fn interrupt_mailbox(
97 &self,
98 mailbox_id: &str,
99 now: u64,
100 ) -> Result<MailboxInterrupt, MailboxStoreError>;
101
102 async fn extend_lease(
107 &self,
108 entry_id: &str,
109 claim_token: &str,
110 extension_ms: u64,
111 now: u64,
112 ) -> Result<bool, MailboxStoreError>;
113
114 async fn purge_terminal_mailbox_entries(
116 &self,
117 older_than: u64,
118 ) -> Result<usize, MailboxStoreError>;
119}
120
121pub trait MailboxStore: MailboxWriter {}
122
123impl<T: MailboxWriter + ?Sized> MailboxStore for T {}