use crate::core::context_data::ContextData;
use crate::core::control::PipelineResult;
use crate::core::trace::RunOutcome;
use crate::error::OrkaError;
use crate::pipeline::definition::Pipeline;
use async_trait::async_trait;
#[async_trait]
pub trait PipelineRunner<TData, Err>: Send + Sync
where
TData: 'static + Send + Sync,
Err: std::error::Error + From<OrkaError> + Send + Sync + 'static,
{
async fn run(&self, ctx_data: ContextData<TData>) -> Result<PipelineResult, Err>;
async fn run_with_outcome(&self, ctx_data: ContextData<TData>) -> (Result<PipelineResult, Err>, RunOutcome) {
let result = self.run(ctx_data).await;
let outcome = match &result {
Ok(PipelineResult::Completed) => RunOutcome::Completed,
Ok(PipelineResult::Stopped) => RunOutcome::Stopped,
Ok(PipelineResult::Cancelled) => RunOutcome::Cancelled,
Err(e) => RunOutcome::Errored {
step: String::new(),
message: e.to_string(),
},
};
(result, outcome)
}
}
#[async_trait]
impl<TData, Err> PipelineRunner<TData, Err> for Pipeline<TData, Err>
where
TData: 'static + Send + Sync,
Err: std::error::Error + From<OrkaError> + Send + Sync + 'static,
{
async fn run(&self, ctx_data: ContextData<TData>) -> Result<PipelineResult, Err> {
Pipeline::run(self, ctx_data).await
}
async fn run_with_outcome(&self, ctx_data: ContextData<TData>) -> (Result<PipelineResult, Err>, RunOutcome) {
Pipeline::run_with_outcome(self, ctx_data).await
}
}