datum-agent 0.9.1

Embeddable Datum job registry and lifecycle supervisor
Documentation
use std::time::Duration;

use datum::StreamInstrumentationRegistry;

use crate::{AgentResult, JobRegistry, JobRegistryHandle};

/// Configuration for an embeddable Datum agent.
#[derive(Debug, Clone)]
pub struct AgentConfig {
    /// How often the registry polls `StreamCompletion::try_wait()` for running jobs.
    pub poll_interval: Duration,
    /// Per-subscriber lifecycle event buffer capacity.
    pub event_buffer: usize,
    /// Registry sampled by DCP metrics subscriptions.
    pub instrumentation: StreamInstrumentationRegistry,
}

impl Default for AgentConfig {
    fn default() -> Self {
        Self {
            poll_interval: Duration::from_millis(10),
            event_buffer: 1_024,
            instrumentation: StreamInstrumentationRegistry::new(),
        }
    }
}

/// Minimal embeddable entrypoint for the local agent.
pub struct Agent;

impl Agent {
    pub fn start() -> AgentResult<AgentHandle> {
        Self::start_with_config(AgentConfig::default())
    }

    pub fn start_with_config(config: AgentConfig) -> AgentResult<AgentHandle> {
        let instrumentation = config.instrumentation.clone();
        Ok(AgentHandle {
            registry: JobRegistry::start(config)?,
            instrumentation,
        })
    }
}

/// Handle returned by [`Agent::start`] and [`Agent::start_with_config`].
#[derive(Clone)]
pub struct AgentHandle {
    registry: JobRegistryHandle,
    instrumentation: StreamInstrumentationRegistry,
}

impl AgentHandle {
    #[must_use]
    pub fn registry(&self) -> &JobRegistryHandle {
        &self.registry
    }

    #[must_use]
    pub fn instrumentation_registry(&self) -> &StreamInstrumentationRegistry {
        &self.instrumentation
    }

    pub fn into_registry(self) -> JobRegistryHandle {
        self.registry
    }
}