pub mod config;
pub mod lifecycle;
pub use config::{BackendConfig, RuntimeConfig, RuntimeConfigBuilder};
pub use lifecycle::{KernelRuntime, LifecycleState, RuntimeBuilder, RuntimeHandle};
use std::sync::Arc;
use std::time::Duration;
pub const DEFAULT_DRAIN_TIMEOUT: Duration = Duration::from_secs(30);
pub const DEFAULT_HEALTH_CHECK_INTERVAL: Duration = Duration::from_secs(10);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RuntimePreset {
Development,
Production,
HighPerformance,
Testing,
}
impl RuntimePreset {
pub fn to_config(&self) -> RuntimeConfig {
match self {
Self::Development => RuntimeConfig::development(),
Self::Production => RuntimeConfig::production(),
Self::HighPerformance => RuntimeConfig::high_performance(),
Self::Testing => RuntimeConfig::testing(),
}
}
}
#[derive(Debug, Clone, Default)]
pub struct RuntimeStats {
pub kernels_registered: usize,
pub kernels_active: usize,
pub messages_processed: u64,
pub messages_in_flight: u64,
pub gpu_memory_bytes: u64,
pub gpu_memory_peak_bytes: u64,
pub uptime_secs: u64,
}
pub type ShutdownSignal = tokio::sync::watch::Receiver<bool>;
pub fn shutdown_channel() -> (tokio::sync::watch::Sender<bool>, ShutdownSignal) {
tokio::sync::watch::channel(false)
}
#[derive(Debug, Clone)]
pub enum RuntimeEvent {
Starting,
Started,
Draining,
Stopped,
KernelRegistered {
id: String,
},
KernelUnregistered {
id: String,
},
ConfigReloaded,
HealthCheckCompleted {
healthy: bool,
},
}
pub type RuntimeEventCallback = Arc<dyn Fn(RuntimeEvent) + Send + Sync>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_runtime_preset_to_config() {
let dev_config = RuntimePreset::Development.to_config();
assert!(!dev_config.gpu_enabled);
let prod_config = RuntimePreset::Production.to_config();
assert!(prod_config.gpu_enabled);
}
#[test]
fn test_shutdown_channel() {
let (tx, rx) = shutdown_channel();
assert!(!*rx.borrow());
tx.send(true).unwrap();
assert!(*rx.borrow());
}
}