keel_events/handler.rs
1use crate::types::{InputType, KeelInput};
2
3/// Result of handling an input.
4#[derive(Debug)]
5pub enum HandlerResponse {
6 /// Input was processed successfully.
7 Processed,
8 /// Input was suppressed (e.g., heartbeat "all clear" response).
9 Suppressed,
10 /// Input should be forwarded to another handler or agent.
11 Forward {
12 to: String,
13 payload: serde_json::Value,
14 },
15 /// Handler encountered an error.
16 Error(String),
17}
18
19/// Trait for handling inputs from the event queue.
20///
21/// Implement this for each kind of processor (message handler, heartbeat
22/// handler, webhook handler, etc.).
23#[async_trait::async_trait]
24pub trait InputHandler: Send + Sync {
25 /// Process a single input, returning the outcome.
26 async fn handle(&self, input: &KeelInput) -> anyhow::Result<HandlerResponse>;
27
28 /// Return true if this handler should receive the given input type.
29 fn handles(&self, input_type: &InputType) -> bool;
30}