use async_trait::async_trait;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct RunId(pub i64);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StepId(pub i64);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RunStatus {
Completed,
Failed { error: String },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StepStatus {
Completed,
Failed { error: String, attempt: u32 },
}
#[async_trait]
pub trait Recorder: Send + Sync {
async fn start_run(&self, pipeline_name: &str, entity_id: &str) -> anyhow::Result<RunId>;
async fn start_step(
&self,
run_id: RunId,
step_name: &str,
step_index: u32,
) -> anyhow::Result<StepId>;
async fn complete_step(&self, step_id: StepId, status: StepStatus) -> anyhow::Result<()>;
async fn complete_run(&self, run_id: RunId, status: RunStatus) -> anyhow::Result<()>;
}
#[derive(Debug, Clone, Default)]
pub struct NoopRecorder;
impl NoopRecorder {
pub fn new() -> Self {
Self
}
}
#[async_trait]
impl Recorder for NoopRecorder {
async fn start_run(&self, _pipeline_name: &str, _entity_id: &str) -> anyhow::Result<RunId> {
Ok(RunId(0))
}
async fn start_step(
&self,
_run_id: RunId,
_step_name: &str,
_step_index: u32,
) -> anyhow::Result<StepId> {
Ok(StepId(0))
}
async fn complete_step(&self, _step_id: StepId, _status: StepStatus) -> anyhow::Result<()> {
Ok(())
}
async fn complete_run(&self, _run_id: RunId, _status: RunStatus) -> anyhow::Result<()> {
Ok(())
}
}