mecha10-runtime
Runtime supervisor for Mecha10 nodes - launching, monitoring, and lifecycle management.
Features
- Node Supervision: Launch and supervise multiple nodes with automatic restart policies
- Health Checking: Monitor node health with customizable check intervals
- Graceful Shutdown: Handle shutdown signals (SIGTERM, SIGINT, Ctrl+C) with configurable timeouts
- Restart Policies: Never, OnFailure (with exponential backoff), or Always restart
- Dynamic Launcher: Optional service for dynamically launching and managing nodes
- Flexible Logging: Pretty, JSON, or Compact output formats with configurable log levels
Installation
[]
= "0.1.0"
= "0.1"
= "1.0"
Quick Start
Basic Single Node
use *;
use Result;
async
Multiple Nodes with Restart Policy
use *;
use Duration;
async
Dynamic Node Launcher
use *;
async
Runtime Configuration
Log Formats
// Pretty format (human-readable, colored)
builder
.log_format
.build;
// JSON format (structured logs for parsing)
builder
.log_format
.build;
// Compact format (minimal output)
builder
.log_format
.build;
Restart Policies
// Never restart failed nodes
builder
.restart_policy
.build;
// Restart on failure with exponential backoff
builder
.restart_policy
.build;
// Always restart with constant backoff
builder
.restart_policy
.build;
NodeRunner Trait
Implement the NodeRunner trait for each node type:
Health Checking
// Custom health check logic
async
// Access health checker from runtime
let health_checker = runtime.health_checker;
let all_statuses = health_checker.check_all.await;
for in all_statuses
Graceful Shutdown
The runtime automatically handles shutdown signals:
// Runs until Ctrl+C or SIGTERM
runtime.run_nodes.await?;
// Custom shutdown timeout
builder
.shutdown_timeout
.build;
// Custom shutdown logic in nodes
async
Architecture
Runtime
├── Supervisor (node lifecycle management)
│ ├── Launch nodes
│ ├── Monitor health
│ ├── Handle restarts
│ └── Coordinate shutdown
├── HealthChecker (health monitoring)
│ ├── Register nodes
│ ├── Track status
│ └── Report health
├── Launcher (dynamic node management) [optional]
│ ├── Register node factories
│ ├── Launch on demand
│ └── Stop running nodes
└── ShutdownHandle (graceful shutdown)
├── Signal handling
└── Broadcast to nodes
Benefits
- 90% Code Reduction: Generated projects go from 180 lines of boilerplate to ~20 lines
- Consistent Behavior: All projects use the same tested runtime logic
- Flexible Configuration: Builder pattern for easy customization
- Production Ready: Health checking, restart policies, graceful shutdown
- Observable: Structured logging with multiple output formats
Examples
See the rover-robot example for a complete demonstration of using mecha10-runtime.
License
MIT