1use std::future::Future;
4
5use crate::types::*;
6
7pub trait WorkflowStore: Send + Sync + 'static {
15 fn create_namespace(
18 &self,
19 name: &str,
20 ) -> impl Future<Output = anyhow::Result<()>> + Send;
21
22 fn list_namespaces(
23 &self,
24 ) -> impl Future<Output = anyhow::Result<Vec<NamespaceRecord>>> + Send;
25
26 fn delete_namespace(
27 &self,
28 name: &str,
29 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
30
31 fn get_namespace_stats(
32 &self,
33 namespace: &str,
34 ) -> impl Future<Output = anyhow::Result<NamespaceStats>> + Send;
35
36 fn create_workflow(
39 &self,
40 workflow: &WorkflowRecord,
41 ) -> impl Future<Output = anyhow::Result<()>> + Send;
42
43 fn get_workflow(
44 &self,
45 id: &str,
46 ) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
47
48 fn list_workflows(
49 &self,
50 namespace: &str,
51 status: Option<WorkflowStatus>,
52 workflow_type: Option<&str>,
53 search_attrs_filter: Option<&str>,
54 limit: i64,
55 offset: i64,
56 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
57
58 fn list_archivable_workflows(
62 &self,
63 cutoff: f64,
64 limit: i64,
65 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
66
67 fn mark_archived_and_purge(
72 &self,
73 workflow_id: &str,
74 archive_uri: &str,
75 archived_at: f64,
76 ) -> impl Future<Output = anyhow::Result<()>> + Send;
77
78 fn upsert_search_attributes(
83 &self,
84 workflow_id: &str,
85 patch_json: &str,
86 ) -> impl Future<Output = anyhow::Result<()>> + Send;
87
88 fn update_workflow_status(
89 &self,
90 id: &str,
91 status: WorkflowStatus,
92 result: Option<&str>,
93 error: Option<&str>,
94 ) -> impl Future<Output = anyhow::Result<()>> + Send;
95
96 fn claim_workflow(
97 &self,
98 id: &str,
99 worker_id: &str,
100 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
101
102 fn mark_workflow_dispatchable(
107 &self,
108 workflow_id: &str,
109 ) -> impl Future<Output = anyhow::Result<()>> + Send;
110
111 fn claim_workflow_task(
116 &self,
117 task_queue: &str,
118 worker_id: &str,
119 ) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
120
121 fn release_workflow_task(
125 &self,
126 workflow_id: &str,
127 worker_id: &str,
128 ) -> impl Future<Output = anyhow::Result<()>> + Send;
129
130 fn release_stale_dispatch_leases(
135 &self,
136 now: f64,
137 timeout_secs: f64,
138 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
139
140 fn append_event(
143 &self,
144 event: &WorkflowEvent,
145 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
146
147 fn list_events(
148 &self,
149 workflow_id: &str,
150 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowEvent>>> + Send;
151
152 fn get_event_count(
153 &self,
154 workflow_id: &str,
155 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
156
157 fn create_activity(
160 &self,
161 activity: &WorkflowActivity,
162 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
163
164 fn get_activity(
166 &self,
167 id: i64,
168 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
169
170 fn get_activity_by_workflow_seq(
174 &self,
175 workflow_id: &str,
176 seq: i32,
177 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
178
179 fn claim_activity(
180 &self,
181 task_queue: &str,
182 worker_id: &str,
183 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
184
185 fn requeue_activity_for_retry(
190 &self,
191 id: i64,
192 next_attempt: i32,
193 next_scheduled_at: f64,
194 ) -> impl Future<Output = anyhow::Result<()>> + Send;
195
196 fn complete_activity(
197 &self,
198 id: i64,
199 result: Option<&str>,
200 error: Option<&str>,
201 failed: bool,
202 ) -> impl Future<Output = anyhow::Result<()>> + Send;
203
204 fn heartbeat_activity(
205 &self,
206 id: i64,
207 details: Option<&str>,
208 ) -> impl Future<Output = anyhow::Result<()>> + Send;
209
210 fn get_timed_out_activities(
211 &self,
212 now: f64,
213 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowActivity>>> + Send;
214
215 fn cancel_pending_activities(
222 &self,
223 workflow_id: &str,
224 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
225
226 fn cancel_pending_timers(
230 &self,
231 workflow_id: &str,
232 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
233
234 fn create_timer(
235 &self,
236 timer: &WorkflowTimer,
237 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
238
239 fn get_timer_by_workflow_seq(
243 &self,
244 workflow_id: &str,
245 seq: i32,
246 ) -> impl Future<Output = anyhow::Result<Option<WorkflowTimer>>> + Send;
247
248 fn fire_due_timers(
249 &self,
250 now: f64,
251 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowTimer>>> + Send;
252
253 fn send_signal(
256 &self,
257 signal: &WorkflowSignal,
258 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
259
260 fn consume_signals(
261 &self,
262 workflow_id: &str,
263 name: &str,
264 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowSignal>>> + Send;
265
266 fn create_schedule(
269 &self,
270 schedule: &WorkflowSchedule,
271 ) -> impl Future<Output = anyhow::Result<()>> + Send;
272
273 fn get_schedule(
274 &self,
275 namespace: &str,
276 name: &str,
277 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
278
279 fn list_schedules(
280 &self,
281 namespace: &str,
282 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowSchedule>>> + Send;
283
284 fn update_schedule_last_run(
285 &self,
286 namespace: &str,
287 name: &str,
288 last_run_at: f64,
289 next_run_at: f64,
290 workflow_id: &str,
291 ) -> impl Future<Output = anyhow::Result<()>> + Send;
292
293 fn delete_schedule(
294 &self,
295 namespace: &str,
296 name: &str,
297 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
298
299 fn update_schedule(
307 &self,
308 namespace: &str,
309 name: &str,
310 patch: &SchedulePatch,
311 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
312
313 fn set_schedule_paused(
320 &self,
321 namespace: &str,
322 name: &str,
323 paused: bool,
324 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
325
326 fn register_worker(
329 &self,
330 worker: &WorkflowWorker,
331 ) -> impl Future<Output = anyhow::Result<()>> + Send;
332
333 fn heartbeat_worker(
334 &self,
335 id: &str,
336 now: f64,
337 ) -> impl Future<Output = anyhow::Result<()>> + Send;
338
339 fn list_workers(
340 &self,
341 namespace: &str,
342 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowWorker>>> + Send;
343
344 fn remove_dead_workers(
345 &self,
346 cutoff: f64,
347 ) -> impl Future<Output = anyhow::Result<Vec<String>>> + Send;
348
349 fn create_api_key(
352 &self,
353 key_hash: &str,
354 prefix: &str,
355 label: Option<&str>,
356 created_at: f64,
357 ) -> impl Future<Output = anyhow::Result<()>> + Send;
358
359 fn validate_api_key(
360 &self,
361 key_hash: &str,
362 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
363
364 fn list_api_keys(
365 &self,
366 ) -> impl Future<Output = anyhow::Result<Vec<ApiKeyRecord>>> + Send;
367
368 fn revoke_api_key(
369 &self,
370 prefix: &str,
371 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
372
373 fn api_keys_empty(&self) -> impl Future<Output = anyhow::Result<bool>> + Send;
377
378 fn get_api_key_by_label(
384 &self,
385 label: &str,
386 ) -> impl Future<Output = anyhow::Result<Option<ApiKeyRecord>>> + Send;
387
388 fn list_child_workflows(
391 &self,
392 parent_id: &str,
393 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
394
395 fn create_snapshot(
398 &self,
399 workflow_id: &str,
400 event_seq: i32,
401 state_json: &str,
402 ) -> impl Future<Output = anyhow::Result<()>> + Send;
403
404 fn get_latest_snapshot(
405 &self,
406 workflow_id: &str,
407 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSnapshot>>> + Send;
408
409 fn get_queue_stats(
412 &self,
413 namespace: &str,
414 ) -> impl Future<Output = anyhow::Result<Vec<QueueStats>>> + Send;
415
416 fn try_acquire_scheduler_lock(
424 &self,
425 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
426
427 }