use async_trait::async_trait;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StepError {
#[error("retryable: {0}")]
Retryable(#[source] anyhow::Error),
#[error("permanent: {0}")]
Permanent(#[source] anyhow::Error),
}
impl StepError {
pub fn retryable(err: impl Into<anyhow::Error>) -> Self {
Self::Retryable(err.into())
}
pub fn permanent(err: impl Into<anyhow::Error>) -> Self {
Self::Permanent(err.into())
}
pub fn is_retryable(&self) -> bool {
matches!(self, Self::Retryable(_))
}
}
#[async_trait]
pub trait Step: Send + Sync {
type Input: Send + Sync + Clone;
type Output: Send + Sync;
fn name(&self) -> &'static str;
async fn execute(&self, input: Self::Input) -> Result<Self::Output, StepError>;
}