Skip to main content

Module supervisor

Module supervisor 

Source
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§

MetricsSnapshot
Plain-data snapshot of supervisor metrics.
SpawnOptions
Per-service spawn configuration.
Supervisor
The central supervisor.
SupervisorConfig
Configuration for the Supervisor.
SupervisorMetrics
Atomic counters for supervisor-level metrics.