Expand description
The Supervisor — manages a fleet of TradingServices.
Replaces the naive tokio::spawn pattern with a structured supervision
tree built on:
TaskTracker— tracks spawned tasks without accumulating results, preventing memory leaks in long-running processes.CancellationToken— propagates graceful shutdown through the service hierarchy.
§Architecture
┌─────────────────────────────────────────────────┐
│ Supervisor │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Market │ │ Risk │ │ Execution│ ... │
│ │ Feed │ │ Engine │ │ Service │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ TaskTracker ◄── tracks all spawned tasks │
│ CancellationToken ◄── shutdown signal tree │
│ BackoffState[] ◄── per-service restart state │
│ ServiceLifecycle[] ◄── per-service state machine│
└─────────────────────────────────────────────────┘§Usage
ⓘ
use rustrade_supervisor::{Supervisor, SupervisorConfig};
let supervisor = Supervisor::new(SupervisorConfig::default());
supervisor.spawn_service(Box::new(my_market_feed));
supervisor.spawn_service(Box::new(my_risk_engine));
supervisor.run_until_shutdown().await?;Structs§
- Metrics
Snapshot - Plain-data snapshot of supervisor metrics.
- Spawn
Options - Per-service spawn configuration.
- Supervisor
- The central supervisor.
- Supervisor
Config - Configuration for the
Supervisor. - Supervisor
Metrics - Atomic counters for supervisor-level metrics.