lash_core/runtime/process/
registry.rs1use crate::plugin::PluginError;
2
3use super::events::{
4 ProcessAwaitOutput, ProcessEvent, ProcessEventAppendRequest, ProcessEventAppendResult,
5};
6use super::model::{
7 ProcessExternalRef, ProcessHandleDescriptor, ProcessHandleGrant, ProcessHandleGrantEntry,
8 ProcessLease, ProcessLeaseCompletion, ProcessListFilter, ProcessRecord, ProcessRegistration,
9 ProcessSessionDeleteReport, SessionScope, WaitState,
10};
11
12#[async_trait::async_trait]
14pub trait ProcessRegistry: Send + Sync {
15 fn durability_tier(&self) -> crate::DurabilityTier {
18 crate::DurabilityTier::Inline
19 }
20
21 async fn register_process(
22 &self,
23 registration: ProcessRegistration,
24 ) -> Result<ProcessRecord, PluginError>;
25
26 async fn set_external_ref(
33 &self,
34 process_id: &str,
35 external_ref: ProcessExternalRef,
36 ) -> Result<ProcessRecord, PluginError>;
37
38 async fn grant_handle(
39 &self,
40 session_scope: &SessionScope,
41 process_id: &str,
42 descriptor: ProcessHandleDescriptor,
43 ) -> Result<ProcessHandleGrant, PluginError>;
44
45 async fn revoke_handle(
46 &self,
47 session_scope: &SessionScope,
48 process_id: &str,
49 ) -> Result<(), PluginError>;
50
51 async fn transfer_handle_grants(
52 &self,
53 from_scope: &SessionScope,
54 to_scope: &SessionScope,
55 process_ids: &[String],
56 ) -> Result<(), PluginError>;
57
58 async fn list_handle_grants(
59 &self,
60 session_scope: &SessionScope,
61 ) -> Result<Vec<ProcessHandleGrantEntry>, PluginError>;
62
63 async fn list_live_handle_grants(
64 &self,
65 session_scope: &SessionScope,
66 ) -> Result<Vec<ProcessHandleGrantEntry>, PluginError> {
67 Ok(self
68 .list_handle_grants(session_scope)
69 .await?
70 .into_iter()
71 .filter(|(_, record)| !record.is_terminal())
72 .collect())
73 }
74
75 async fn has_handle_grant(
76 &self,
77 session_scope: &SessionScope,
78 process_id: &str,
79 ) -> Result<bool, PluginError> {
80 Ok(self
81 .list_handle_grants(session_scope)
82 .await?
83 .into_iter()
84 .any(|(grant, _)| grant.process_id == process_id))
85 }
86
87 async fn handle_grants_for_process(
88 &self,
89 process_id: &str,
90 ) -> Result<Vec<ProcessHandleGrant>, PluginError>;
91
92 async fn delete_session_process_state(
93 &self,
94 session_id: &str,
95 ) -> Result<ProcessSessionDeleteReport, PluginError>;
96
97 async fn append_event(
98 &self,
99 process_id: &str,
100 request: ProcessEventAppendRequest,
101 ) -> Result<ProcessEventAppendResult, PluginError>;
102
103 async fn events_after(
104 &self,
105 process_id: &str,
106 after_sequence: u64,
107 ) -> Result<Vec<ProcessEvent>, PluginError>;
108
109 async fn count_events_through(
116 &self,
117 process_id: &str,
118 event_type: &str,
119 up_to_sequence: u64,
120 ) -> Result<u64, PluginError> {
121 Ok(self
122 .events_after(process_id, 0)
123 .await?
124 .into_iter()
125 .filter(|event| event.sequence <= up_to_sequence && event.event_type == event_type)
126 .count() as u64)
127 }
128
129 async fn recent_events(
135 &self,
136 process_id: &str,
137 limit: usize,
138 ) -> Result<Vec<ProcessEvent>, PluginError> {
139 let mut events = self.events_after(process_id, 0).await?;
140 if events.len() > limit {
141 events.drain(..events.len() - limit);
142 }
143 Ok(events)
144 }
145
146 async fn wake_events_after(
147 &self,
148 process_id: &str,
149 after_sequence: u64,
150 ) -> Result<Vec<ProcessEvent>, PluginError>;
151
152 async fn wait_event_after(
153 &self,
154 process_id: &str,
155 event_type: &str,
156 after_sequence: u64,
157 ) -> Result<ProcessEvent, PluginError>;
158
159 async fn await_process(&self, process_id: &str) -> Result<ProcessAwaitOutput, PluginError>;
160
161 async fn complete_process(
162 &self,
163 process_id: &str,
164 await_output: ProcessAwaitOutput,
165 ) -> Result<ProcessRecord, PluginError>;
166
167 async fn set_process_wait(
168 &self,
169 process_id: &str,
170 wait: WaitState,
171 ) -> Result<ProcessRecord, PluginError>;
172
173 async fn clear_process_wait(&self, process_id: &str) -> Result<ProcessRecord, PluginError>;
174
175 async fn get_process(&self, process_id: &str) -> Option<ProcessRecord>;
176
177 async fn list_processes(
178 &self,
179 filter: &ProcessListFilter,
180 ) -> Result<Vec<ProcessRecord>, PluginError>;
181
182 async fn ack_wake(&self, process_id: &str, sequence: u64) -> Result<(), PluginError>;
183
184 async fn list_non_terminal(&self) -> Result<Vec<ProcessRecord>, PluginError>;
192
193 async fn claim_process_lease(
201 &self,
202 process_id: &str,
203 owner_id: &str,
204 lease_ttl_ms: u64,
205 ) -> Result<ProcessLease, PluginError>;
206
207 async fn renew_process_lease(
214 &self,
215 lease: &ProcessLease,
216 lease_ttl_ms: u64,
217 ) -> Result<ProcessLease, PluginError>;
218
219 async fn complete_process_lease(
227 &self,
228 completion: &ProcessLeaseCompletion,
229 ) -> Result<(), PluginError>;
230}