cognis_graph/checkpoint/
mod.rs1use async_trait::async_trait;
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8use cognis_core::Result;
9
10use crate::state::GraphState;
11
12mod in_memory;
13pub use in_memory::InMemoryCheckpointer;
14
15pub mod serializer;
16#[cfg(feature = "serializer-cbor")]
17pub use serializer::CborSerializer;
18pub use serializer::{CheckpointSerializer, JsonSerializer};
19
20#[cfg(feature = "sqlite")]
21pub mod sqlite;
22#[cfg(feature = "sqlite")]
23pub use sqlite::SqliteCheckpointer;
24
25#[cfg(feature = "postgres")]
26pub mod postgres;
27#[cfg(feature = "postgres")]
28pub use postgres::PostgresCheckpointer;
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ActiveSnapshot {
34 pub node_name: String,
36 pub payload: Option<serde_json::Value>,
38}
39
40#[async_trait]
42pub trait Checkpointer<S: GraphState>: Send + Sync {
43 async fn save(&self, run_id: Uuid, step: u64, state: &S) -> Result<()>;
45
46 async fn load(&self, run_id: Uuid, step: Option<u64>) -> Result<Option<S>>;
48
49 async fn list(&self, run_id: Uuid) -> Result<Vec<u64>>;
51
52 async fn save_active(&self, run_id: Uuid, step: u64, active: &[ActiveSnapshot]) -> Result<()> {
57 let _ = (run_id, step, active);
58 Ok(())
59 }
60
61 async fn load_active(&self, run_id: Uuid, step: u64) -> Result<Vec<ActiveSnapshot>> {
63 let _ = (run_id, step);
64 Ok(Vec::new())
65 }
66}