1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Node runner trait and types
use crateHealthStatus;
use Result;
use 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()
/// }
/// }
/// }
/// }
/// ```