sayiir_persistence/lib.rs
1//! Persistence layer for workflow execution state.
2//!
3//! This crate provides traits and implementations for persisting workflow
4//! execution state, enabling distributed execution with checkpoint/restore
5//! capabilities.
6//!
7//! # Trait Hierarchy
8//!
9//! The persistence layer is built around focused sub-traits:
10//!
11//! - **[`SnapshotStore`]**: Core CRUD for workflow snapshots (5 methods).
12//! - **[`SignalStore`]**: Cancel + pause signal primitives with default composite
13//! implementations (3 required + 3 default methods).
14//! - **[`TaskClaimStore`]**: Distributed task claiming (4 methods, opt-in).
15//! - **[`PersistentBackend`]**: Supertrait = `SnapshotStore + SignalStore`,
16//! blanket-implemented so backends never need to impl it directly.
17//!
18//! A minimal backend only needs **8 methods** (`SnapshotStore` + 3 `SignalStore`
19//! primitives) to satisfy `PersistentBackend`.
20//!
21//! # Example
22//!
23//! ```rust,no_run
24//! use sayiir_persistence::{InMemoryBackend, SnapshotStore};
25//! use sayiir_core::snapshot::WorkflowSnapshot;
26//!
27//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
28//! // Create a backend (could be Redis, PostgreSQL, etc.)
29//! let backend = InMemoryBackend::new();
30//!
31//! // Save a snapshot
32//! let snapshot = WorkflowSnapshot::new("instance-123".to_string(), "hash-abc".to_string());
33//! backend.save_snapshot(&snapshot).await?;
34//!
35//! // Load it back
36//! let loaded = backend.load_snapshot("instance-123").await?;
37//! # Ok(())
38//! # }
39//! ```
40
41mod backend;
42mod in_memory;
43
44pub use backend::{BackendError, PersistentBackend, SignalStore, SnapshotStore, TaskClaimStore};
45pub use in_memory::InMemoryBackend;