use serde::{Deserialize, Serialize};
pub trait SessionLedger: Send + Sync {
fn get_session(&self, task_id: &str) -> anyhow::Result<Option<SessionRecord>>;
fn upsert_session(&self, task_id: &str, version: &VersionedSession) -> anyhow::Result<bool>;
fn task_is_known(&self, task_id: &str) -> anyhow::Result<bool>;
fn task_attempt(&self, task_id: &str) -> anyhow::Result<i64>;
fn list_faults(&self, task_id: &str) -> anyhow::Result<Vec<FaultRecord>>;
fn insert_fault(&self, fault: &FaultRecord) -> anyhow::Result<i64>;
fn emit(&self, kind: &str, data: serde_json::Value);
fn note_alert(&self, line: String);
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SessionRecord {
pub session_id: String,
pub task_id: String,
pub agent_state: String,
pub delivery_state: String,
pub resource_state: String,
pub recovery_substate: String,
pub desired_json: String,
pub observed_json: String,
pub generation: i64,
pub seq: i64,
pub backend_ref: String,
pub mismatch_count: i64,
pub updated_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct VersionedSession {
pub agent_state: String,
pub delivery_state: String,
pub resource_state: String,
pub recovery_substate: String,
pub desired_json: String,
pub observed_json: String,
pub generation: i64,
pub seq: i64,
pub backend_ref: String,
pub mismatch_count: i64,
pub updated_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FaultRecord {
pub id: i64,
pub task_id: String,
pub session_id: String,
pub generation: i64,
pub seq: i64,
pub desired_json: String,
pub observed_json: String,
pub intent: String,
pub attempt: i64,
pub backend_ref: String,
pub kind: String,
pub reason: String,
pub state: String,
pub created_at: i64,
}