1pub mod postgres;
2pub mod sqlite;
3
4use std::future::Future;
5
6use crate::types::*;
7
8pub trait WorkflowStore: Send + Sync + 'static {
16 fn create_namespace(
19 &self,
20 name: &str,
21 ) -> impl Future<Output = anyhow::Result<()>> + Send;
22
23 fn list_namespaces(
24 &self,
25 ) -> impl Future<Output = anyhow::Result<Vec<NamespaceRecord>>> + Send;
26
27 fn delete_namespace(
28 &self,
29 name: &str,
30 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
31
32 fn get_namespace_stats(
33 &self,
34 namespace: &str,
35 ) -> impl Future<Output = anyhow::Result<NamespaceStats>> + Send;
36
37 fn create_workflow(
40 &self,
41 workflow: &WorkflowRecord,
42 ) -> impl Future<Output = anyhow::Result<()>> + Send;
43
44 fn get_workflow(
45 &self,
46 id: &str,
47 ) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
48
49 fn list_workflows(
50 &self,
51 namespace: &str,
52 status: Option<WorkflowStatus>,
53 workflow_type: Option<&str>,
54 search_attrs_filter: Option<&str>,
55 limit: i64,
56 offset: i64,
57 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
58
59 fn list_archivable_workflows(
63 &self,
64 cutoff: f64,
65 limit: i64,
66 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
67
68 fn mark_archived_and_purge(
73 &self,
74 workflow_id: &str,
75 archive_uri: &str,
76 archived_at: f64,
77 ) -> impl Future<Output = anyhow::Result<()>> + Send;
78
79 fn upsert_search_attributes(
84 &self,
85 workflow_id: &str,
86 patch_json: &str,
87 ) -> impl Future<Output = anyhow::Result<()>> + Send;
88
89 fn update_workflow_status(
90 &self,
91 id: &str,
92 status: WorkflowStatus,
93 result: Option<&str>,
94 error: Option<&str>,
95 ) -> impl Future<Output = anyhow::Result<()>> + Send;
96
97 fn claim_workflow(
98 &self,
99 id: &str,
100 worker_id: &str,
101 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
102
103 fn mark_workflow_dispatchable(
108 &self,
109 workflow_id: &str,
110 ) -> impl Future<Output = anyhow::Result<()>> + Send;
111
112 fn claim_workflow_task(
117 &self,
118 task_queue: &str,
119 worker_id: &str,
120 ) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
121
122 fn release_workflow_task(
126 &self,
127 workflow_id: &str,
128 worker_id: &str,
129 ) -> impl Future<Output = anyhow::Result<()>> + Send;
130
131 fn release_stale_dispatch_leases(
136 &self,
137 now: f64,
138 timeout_secs: f64,
139 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
140
141 fn append_event(
144 &self,
145 event: &WorkflowEvent,
146 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
147
148 fn list_events(
149 &self,
150 workflow_id: &str,
151 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowEvent>>> + Send;
152
153 fn get_event_count(
154 &self,
155 workflow_id: &str,
156 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
157
158 fn create_activity(
161 &self,
162 activity: &WorkflowActivity,
163 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
164
165 fn get_activity(
167 &self,
168 id: i64,
169 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
170
171 fn get_activity_by_workflow_seq(
175 &self,
176 workflow_id: &str,
177 seq: i32,
178 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
179
180 fn claim_activity(
181 &self,
182 task_queue: &str,
183 worker_id: &str,
184 ) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
185
186 fn requeue_activity_for_retry(
191 &self,
192 id: i64,
193 next_attempt: i32,
194 next_scheduled_at: f64,
195 ) -> impl Future<Output = anyhow::Result<()>> + Send;
196
197 fn complete_activity(
198 &self,
199 id: i64,
200 result: Option<&str>,
201 error: Option<&str>,
202 failed: bool,
203 ) -> impl Future<Output = anyhow::Result<()>> + Send;
204
205 fn heartbeat_activity(
206 &self,
207 id: i64,
208 details: Option<&str>,
209 ) -> impl Future<Output = anyhow::Result<()>> + Send;
210
211 fn get_timed_out_activities(
212 &self,
213 now: f64,
214 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowActivity>>> + Send;
215
216 fn cancel_pending_activities(
223 &self,
224 workflow_id: &str,
225 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
226
227 fn cancel_pending_timers(
231 &self,
232 workflow_id: &str,
233 ) -> impl Future<Output = anyhow::Result<u64>> + Send;
234
235 fn create_timer(
236 &self,
237 timer: &WorkflowTimer,
238 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
239
240 fn get_timer_by_workflow_seq(
244 &self,
245 workflow_id: &str,
246 seq: i32,
247 ) -> impl Future<Output = anyhow::Result<Option<WorkflowTimer>>> + Send;
248
249 fn fire_due_timers(
250 &self,
251 now: f64,
252 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowTimer>>> + Send;
253
254 fn send_signal(
257 &self,
258 signal: &WorkflowSignal,
259 ) -> impl Future<Output = anyhow::Result<i64>> + Send;
260
261 fn consume_signals(
262 &self,
263 workflow_id: &str,
264 name: &str,
265 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowSignal>>> + Send;
266
267 fn create_schedule(
270 &self,
271 schedule: &WorkflowSchedule,
272 ) -> impl Future<Output = anyhow::Result<()>> + Send;
273
274 fn get_schedule(
275 &self,
276 namespace: &str,
277 name: &str,
278 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
279
280 fn list_schedules(
281 &self,
282 namespace: &str,
283 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowSchedule>>> + Send;
284
285 fn update_schedule_last_run(
286 &self,
287 namespace: &str,
288 name: &str,
289 last_run_at: f64,
290 next_run_at: f64,
291 workflow_id: &str,
292 ) -> impl Future<Output = anyhow::Result<()>> + Send;
293
294 fn delete_schedule(
295 &self,
296 namespace: &str,
297 name: &str,
298 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
299
300 fn update_schedule(
308 &self,
309 namespace: &str,
310 name: &str,
311 patch: &SchedulePatch,
312 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
313
314 fn set_schedule_paused(
321 &self,
322 namespace: &str,
323 name: &str,
324 paused: bool,
325 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
326
327 fn register_worker(
330 &self,
331 worker: &WorkflowWorker,
332 ) -> impl Future<Output = anyhow::Result<()>> + Send;
333
334 fn heartbeat_worker(
335 &self,
336 id: &str,
337 now: f64,
338 ) -> impl Future<Output = anyhow::Result<()>> + Send;
339
340 fn list_workers(
341 &self,
342 namespace: &str,
343 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowWorker>>> + Send;
344
345 fn remove_dead_workers(
346 &self,
347 cutoff: f64,
348 ) -> impl Future<Output = anyhow::Result<Vec<String>>> + Send;
349
350 fn create_api_key(
353 &self,
354 key_hash: &str,
355 prefix: &str,
356 label: Option<&str>,
357 created_at: f64,
358 ) -> impl Future<Output = anyhow::Result<()>> + Send;
359
360 fn validate_api_key(
361 &self,
362 key_hash: &str,
363 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
364
365 fn list_api_keys(
366 &self,
367 ) -> impl Future<Output = anyhow::Result<Vec<ApiKeyRecord>>> + Send;
368
369 fn revoke_api_key(
370 &self,
371 prefix: &str,
372 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
373
374 fn list_child_workflows(
377 &self,
378 parent_id: &str,
379 ) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
380
381 fn create_snapshot(
384 &self,
385 workflow_id: &str,
386 event_seq: i32,
387 state_json: &str,
388 ) -> impl Future<Output = anyhow::Result<()>> + Send;
389
390 fn get_latest_snapshot(
391 &self,
392 workflow_id: &str,
393 ) -> impl Future<Output = anyhow::Result<Option<WorkflowSnapshot>>> + Send;
394
395 fn get_queue_stats(
398 &self,
399 namespace: &str,
400 ) -> impl Future<Output = anyhow::Result<Vec<QueueStats>>> + Send;
401
402 fn try_acquire_scheduler_lock(
410 &self,
411 ) -> impl Future<Output = anyhow::Result<bool>> + Send;
412}
413
414#[derive(Clone, Debug, serde::Serialize)]
416pub struct ApiKeyRecord {
417 pub prefix: String,
418 pub label: Option<String>,
419 pub created_at: f64,
420}
421
422#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
424pub struct NamespaceRecord {
425 pub name: String,
426 pub created_at: f64,
427}
428
429#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
431pub struct NamespaceStats {
432 pub namespace: String,
433 pub total_workflows: i64,
434 pub running: i64,
435 pub pending: i64,
436 pub completed: i64,
437 pub failed: i64,
438 pub schedules: i64,
439 pub workers: i64,
440}
441
442#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
444pub struct QueueStats {
445 pub queue: String,
446 pub pending_activities: i64,
447 pub running_activities: i64,
448 pub workers: i64,
449}