Skip to main content

kcl_async/
processor.rs

1use async_trait::async_trait;
2
3use crate::{
4    message::input::{
5        InitializeMessage, LeaseLostMessage, ProcessRecordsMessage, ShardEndedMessage,
6        ShutdownMessage, ShutdownRequestedMessage,
7    },
8    transport::Transport,
9};
10
11use super::checkpoint::Checkpointer;
12
13#[async_trait]
14pub trait Processor<T>
15where
16    T: Transport + Send,
17{
18    type Error;
19
20    async fn initialize(&mut self, msg: InitializeMessage) -> Result<(), Self::Error>;
21
22    async fn process_records(
23        &mut self,
24        msg: ProcessRecordsMessage,
25        checkpointer: &mut Checkpointer<'_, T>,
26    ) -> Result<(), Self::Error>;
27
28    async fn shutdown(
29        &mut self,
30        msg: ShutdownMessage,
31        checkpointer: &mut Checkpointer<'_, T>,
32    ) -> Result<(), Self::Error>;
33
34    async fn shutdown_requested(
35        &mut self,
36        msg: ShutdownRequestedMessage,
37        checkpointer: &mut Checkpointer<'_, T>,
38    ) -> Result<(), Self::Error>;
39
40    async fn lease_lost(&mut self, msg: LeaseLostMessage) -> Result<(), Self::Error>;
41
42    async fn shard_ended(&mut self, msg: ShardEndedMessage) -> Result<(), Self::Error>;
43}