use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::error::Result;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JobStateRecord {
pub job_id: String,
pub last_success_at: Option<DateTime<Utc>>,
pub last_error: Option<String>,
pub attempt: u32,
pub next_run_at: Option<DateTime<Utc>>,
pub last_heartbeat_at: Option<DateTime<Utc>>,
#[serde(default)]
pub disabled: bool,
#[serde(default)]
pub schedule_override: Option<String>,
}
#[async_trait]
pub trait JobStore: Send + Sync + 'static {
async fn get(&self, job_id: &str) -> Result<Option<JobStateRecord>>;
async fn list(&self) -> Result<Vec<JobStateRecord>>;
async fn set_next_run(&self, job_id: &str, at: Option<DateTime<Utc>>) -> Result<()>;
async fn set_success(
&self,
job_id: &str,
at: DateTime<Utc>,
next: Option<DateTime<Utc>>,
) -> Result<()>;
async fn set_error(&self, job_id: &str, error: &str, next: Option<DateTime<Utc>>)
-> Result<()>;
async fn set_heartbeat(&self, job_id: &str, at: DateTime<Utc>) -> Result<()>;
async fn set_disabled(&self, job_id: &str, disabled: bool) -> Result<()>;
async fn set_schedule_override(&self, job_id: &str, expr: Option<String>) -> Result<()>;
}