Skip to main content

jamjet_state/
snapshot.rs

1use crate::event::EventSequence;
2use chrono::{DateTime, Utc};
3use jamjet_core::workflow::ExecutionId;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// A point-in-time snapshot of workflow state.
8///
9/// Current state = latest snapshot + events with sequence > snapshot.at_sequence
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Snapshot {
12    pub id: Uuid,
13    pub execution_id: ExecutionId,
14    /// The event sequence number at which this snapshot was taken.
15    pub at_sequence: EventSequence,
16    /// Materialized workflow state at this point.
17    pub state: serde_json::Value,
18    pub created_at: DateTime<Utc>,
19}
20
21impl Snapshot {
22    pub fn new(
23        execution_id: ExecutionId,
24        at_sequence: EventSequence,
25        state: serde_json::Value,
26    ) -> Self {
27        Self {
28            id: Uuid::new_v4(),
29            execution_id,
30            at_sequence,
31            state,
32            created_at: Utc::now(),
33        }
34    }
35}
36
37/// Default number of events between automatic snapshots.
38pub const DEFAULT_SNAPSHOT_INTERVAL: i64 = 50;