use super::{
error::HandlerResult,
model::{
data_flow::{DataFlow, DataFlowState},
messages::DataFlowStatusMessage,
},
};
#[cfg(test)]
use crate::core::db::tx::MockTransaction;
#[async_trait::async_trait]
#[cfg_attr(test, mockall::automock(type Transaction = MockTransaction;))]
#[allow(unused_variables)]
pub trait DataFlowHandler: Send + Sync {
type Transaction;
async fn can_handle(&self, flow: &DataFlow) -> HandlerResult<bool>;
async fn on_start(
&self,
tx: &mut Self::Transaction,
flow: &DataFlow,
) -> HandlerResult<DataFlowStatusMessage>;
async fn on_prepare(
&self,
tx: &mut Self::Transaction,
flow: &DataFlow,
) -> HandlerResult<DataFlowStatusMessage>;
async fn on_terminate(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
async fn on_started(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
async fn on_completed(
&self,
_tx: &mut Self::Transaction,
_flow: &DataFlow,
) -> HandlerResult<()> {
Ok(())
}
async fn on_suspend(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
async fn on_resume(
&self,
tx: &mut Self::Transaction,
flow: &DataFlow,
) -> HandlerResult<DataFlowStatusMessage> {
Ok(DataFlowStatusMessage::builder()
.data_flow_id(flow.id.clone())
.state(DataFlowState::Started)
.build())
}
}