reifydb_core/interface/flow.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::sync::Arc;
5
6use crate::interface::catalog::{flow::FlowId, shape::ShapeId};
7
8/// A row in the system.flow_watermarks virtual table.
9#[derive(Debug, Clone)]
10pub struct FlowWatermarkRow {
11 /// The flow ID.
12 pub flow_id: FlowId,
13 /// The shape this flow subscribes to.
14 pub shape_id: ShapeId,
15 /// The lag: how many versions behind the flow is for this source.
16 pub lag: u64,
17}
18
19/// Concrete IoC service that yields flow watermark rows.
20///
21/// The flow subsystem constructs one of these during startup with a closure
22/// that captures its internal state (tracker, engine, flow catalog). The
23/// `system.flow_watermarks` virtual table and `db.watermarks().flow()`
24/// resolve it from IoC by concrete type.
25///
26/// Lives in `core` so downstream crates (catalog, pkg/reifydb) can name it
27/// without depending on `sub-flow` directly.
28#[derive(Clone)]
29pub struct FlowWatermarkSampler {
30 fetch: Arc<dyn Fn() -> Vec<FlowWatermarkRow> + Send + Sync>,
31}
32
33impl FlowWatermarkSampler {
34 pub fn new<F>(fetch: F) -> Self
35 where
36 F: Fn() -> Vec<FlowWatermarkRow> + Send + Sync + 'static,
37 {
38 Self {
39 fetch: Arc::new(fetch),
40 }
41 }
42
43 pub fn all(&self) -> Vec<FlowWatermarkRow> {
44 (self.fetch)()
45 }
46}