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
//! # rustrade-supervisor
//!
//! Structured service lifecycle management for async trading bots.
//!
//! Every long-running task in a rustrade bot — market feeds, candle
//! pollers, heartbeats, brains — implements [`TradingService`] and is
//! spawned through a [`Supervisor`] that:
//!
//! - Tracks running tasks without accumulating their results (uses
//! `TaskTracker` rather than `JoinSet`).
//! - Propagates graceful shutdown via a root `CancellationToken` that
//! branches to each service.
//! - Restarts failed services with exponential backoff plus full jitter
//! and per-service circuit breakers.
//! - Surfaces lifecycle state (Starting / Running / BackingOff / Stopping
//! / Terminated) and metrics (restarts, active services, uptime) for
//! observability.
//!
//! # Quickstart
//!
//! ```rust,ignore
//! use rustrade_supervisor::{Supervisor, SupervisorConfig, TradingService};
//!
//! let supervisor = Supervisor::new(SupervisorConfig::default());
//! supervisor.spawn_service(Box::new(my_market_feed));
//! supervisor.spawn_service(Box::new(my_risk_engine));
//!
//! // Blocks until Ctrl-C / SIGTERM, then orchestrates graceful shutdown.
//! supervisor.run_until_shutdown().await?;
//! ```
//!
//! # Observability
//!
//! Atomic counters in [`SupervisorMetrics`] are the in-process source of
//! truth and are always available. Enable the `prometheus` feature to
//! mirror them into a crate-local `prometheus::Registry` accessible via
//! the `prometheus::registry` accessor in this crate's `prometheus`
//! submodule. The host service serves `.gather()` from that registry in
//! its `/metrics` handler — rustrade does not own an HTTP layer of its
//! own.
pub use ;
pub use ;
pub use ;
pub use ;