Skip to main content

dataplane_sdk/core/
handler.rs

1//  Copyright (c) 2026 Metaform Systems, Inc
2//
3//  This program and the accompanying materials are made available under the
4//  terms of the Apache License, Version 2.0 which is available at
5//  https://www.apache.org/licenses/LICENSE-2.0
6//
7//    SPDX-License-Identifier: Apache-2.0
8//
9//    Contributors:
10//         Metaform Systems, Inc. - initial API and implementation
11//
12
13use super::{
14    error::HandlerResult,
15    model::{
16        data_flow::{DataFlow, DataFlowState},
17        messages::DataFlowStatusMessage,
18    },
19};
20
21#[cfg(test)]
22use crate::core::db::tx::MockTransaction;
23
24#[async_trait::async_trait]
25#[cfg_attr(test, mockall::automock(type Transaction = MockTransaction;))]
26#[allow(unused_variables)]
27pub trait DataFlowHandler: Send + Sync {
28    type Transaction;
29
30    async fn can_handle(&self, flow: &DataFlow) -> HandlerResult<bool>;
31
32    async fn on_start(
33        &self,
34        tx: &mut Self::Transaction,
35        flow: &DataFlow,
36    ) -> HandlerResult<DataFlowStatusMessage>;
37
38    async fn on_prepare(
39        &self,
40        tx: &mut Self::Transaction,
41        flow: &DataFlow,
42    ) -> HandlerResult<DataFlowStatusMessage>;
43
44    async fn on_terminate(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
45    async fn on_started(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
46
47    async fn on_completed(
48        &self,
49        _tx: &mut Self::Transaction,
50        _flow: &DataFlow,
51    ) -> HandlerResult<()> {
52        Ok(())
53    }
54
55    async fn on_suspend(&self, tx: &mut Self::Transaction, flow: &DataFlow) -> HandlerResult<()>;
56
57    async fn on_resume(
58        &self,
59        tx: &mut Self::Transaction,
60        flow: &DataFlow,
61    ) -> HandlerResult<DataFlowStatusMessage> {
62        Ok(DataFlowStatusMessage::builder()
63            .data_flow_id(flow.id.clone())
64            .state(DataFlowState::Started)
65            .build())
66    }
67}