mecha10-runtime 0.6.5

Runtime supervisor for Mecha10 nodes - launching, monitoring, and lifecycle management
Documentation
//! Node runner trait and types

use crate::health::HealthStatus;
use anyhow::Result;
use async_trait::async_trait;

/// Trait for runnable nodes
///
/// Implement this trait for each node type to integrate with the runtime supervisor.
///
/// # Example
///
/// ```rust
/// use mecha10_runtime::prelude::*;
///
/// struct CameraNode {
///     frame_count: u64,
/// }
///
/// #[async_trait]
/// impl NodeRunner for CameraNode {
///     fn name(&self) -> &str {
///         "camera"
///     }
///
///     async fn run(&mut self) -> anyhow::Result<()> {
///         loop {
///             self.frame_count += 1;
///             tokio::time::sleep(tokio::time::Duration::from_millis(33)).await;
///         }
///     }
///
///     async fn health_check(&self) -> HealthStatus {
///         if self.frame_count > 0 {
///             HealthStatus::Healthy
///         } else {
///             HealthStatus::Unhealthy {
///                 reason: "No frames captured".to_string()
///             }
///         }
///     }
/// }
/// ```
#[async_trait]
pub trait NodeRunner: Send + Sync {
    /// Get the node name
    fn name(&self) -> &str;

    /// Run the node
    ///
    /// This method should contain the main logic for the node.
    /// It will be called by the supervisor and should run until completion or error.
    async fn run(&mut self) -> Result<()>;

    /// Perform a health check
    ///
    /// Override this method to provide custom health checking logic.
    /// By default, nodes are considered healthy.
    async fn health_check(&self) -> HealthStatus {
        HealthStatus::Healthy
    }

    /// Handle shutdown signal
    ///
    /// Override this method to perform cleanup before shutdown.
    /// By default, no special cleanup is performed.
    async fn shutdown(&mut self) -> Result<()> {
        Ok(())
    }
}