made_core/ports/statistics.rs
1//! [`StatisticsPort`] — operational counter surface.
2//!
3//! Every [`DeliberateUseCase`](super) invocation that completes
4//! records its duration and specialty through this port; every
5//! [`OrchestrateUseCase`](super) invocation records the orchestration
6//! duration. Adapters decide where the numbers live — in-memory for
7//! a single replica, external store for multi-replica setups — and
8//! whatever Prometheus / gRPC exposer the composition root wires
9//! reads [`Statistics`] through `snapshot`.
10
11use async_trait::async_trait;
12
13use crate::entities::Statistics;
14use crate::error::DomainError;
15use crate::value_objects::{DurationMs, Specialty};
16
17#[async_trait]
18pub trait StatisticsPort: Send + Sync {
19 /// Record that a deliberation for `specialty` completed in
20 /// `duration`.
21 async fn record_deliberation(
22 &self,
23 specialty: &Specialty,
24 duration: DurationMs,
25 ) -> Result<(), DomainError>;
26
27 /// Record that an orchestration (deliberate + execute) completed
28 /// in `duration`.
29 async fn record_orchestration(&self, duration: DurationMs) -> Result<(), DomainError>;
30
31 /// Read-only snapshot. Callers receive a clone so the returned
32 /// value is safe to serialise without holding any lock.
33 async fn snapshot(&self) -> Result<Statistics, DomainError>;
34}