Skip to main content

kinetic_common/
config.rs

1//! Configuration traits and contexts for Kinetic components.
2
3use kinetic_buffers::{BufferReceiver, BufferSender};
4use kinetic_core::{ComponentId, ShutdownSignal};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7use tokio::task::JoinHandle;
8
9use std::path::PathBuf;
10
11/// Configuration for event acknowledgements (end-to-end delivery tracking).
12#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
13pub struct AcknowledgementsConfig {
14    /// Whether acknowledgements are enabled for this component.
15    pub enabled: bool,
16}
17
18/// Context provided to source components during the build process.
19pub struct SourceContext {
20    pub id: ComponentId,
21    pub pipeline_id: String,
22    pub out: BufferSender,
23    pub error_out: BufferSender,
24    pub shutdown: ShutdownSignal,
25    pub acknowledgements: AcknowledgementsConfig,
26    pub data_dir: Option<PathBuf>,
27}
28
29/// Trait for component configurations that can build a source task.
30pub trait SourceConfig: Send + Sync {
31    fn build(&self, cx: SourceContext) -> anyhow::Result<JoinHandle<()>>;
32}
33
34/// Context provided to transform components during the build process.
35pub struct TransformContext {
36    pub id: ComponentId,
37    pub pipeline_id: String,
38    pub in_rx: BufferReceiver,
39    pub outs: HashMap<String, BufferSender>,
40    pub shutdown: ShutdownSignal,
41    pub data_dir: Option<PathBuf>,
42}
43
44/// Trait for component configurations that can build a transform task.
45pub trait TransformConfig: Send + Sync {
46    fn build(&self, cx: TransformContext) -> anyhow::Result<JoinHandle<()>>;
47}
48
49/// Context provided to sink components during the build process.
50pub struct SinkContext {
51    pub id: ComponentId,
52    pub in_rx: BufferReceiver,
53    pub shutdown: ShutdownSignal,
54    pub acknowledgements: AcknowledgementsConfig,
55    pub data_dir: Option<PathBuf>,
56}
57
58/// Trait for component configurations that can build a sink task.
59pub trait SinkConfig: Send + Sync {
60    fn build(&self, cx: SinkContext) -> anyhow::Result<JoinHandle<()>>;
61}