Skip to main content

foxtive_supervisor/persistence/
mod.rs

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