pub trait NodeRunner: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Trait for runnable nodes
Implement this trait for each node type to integrate with the runtime supervisor.
§Example
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()
}
}
}
}Required Methods§
Sourcefn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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.
Provided Methods§
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Perform a health check
Override this method to provide custom health checking logic. By default, nodes are considered healthy.