Skip to main content

foxtive_supervisor/persistence/
mod.rs

1use serde::{Deserialize, Serialize};
2use crate::enums::TaskState;
3
4mod memory;
5mod fs;
6
7pub use memory::InMemoryStateStore;
8pub use fs::FsStateStore;
9
10/// State of a task that can be persisted across supervisor restarts
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct PersistedTaskState {
13    pub task_id: String,
14    pub last_run_timestamp_secs: Option<u64>,
15    pub last_success_timestamp_secs: Option<u64>,
16    pub failure_count: usize,
17    pub current_attempt: usize,
18    pub current_state: TaskState,
19}
20
21/// Trait for components that persist task state
22#[async_trait::async_trait]
23pub trait TaskStateStore: Send + Sync {
24    /// Save the state of a task
25    async fn save_state(&self, state: PersistedTaskState) -> anyhow::Result<()>;
26
27    /// Load the state of a task by ID
28    async fn load_state(&self, task_id: &str) -> anyhow::Result<Option<PersistedTaskState>>;
29
30    /// Load all saved task states
31    async fn load_all_states(&self) -> anyhow::Result<Vec<PersistedTaskState>>;
32
33    /// Delete the state of a task
34    async fn delete_state(&self, task_id: &str) -> anyhow::Result<()>;
35}