Skip to main content

palladium_runtime/supervisor/
types.rs

1use crate::reactor::Reactor;
2use palladium_actor::{ActorPath, AddrHash, ChildSpec};
3use std::collections::VecDeque;
4use std::time::{Duration, Instant};
5
6/// How a supervisor responds when a child fails.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum SupervisionStrategy {
9    /// Restart only the failed child; siblings are unaffected (REQ-015).
10    OneForOne,
11    /// Stop all children in reverse order, then restart all in original order
12    /// (REQ-016).
13    OneForAll,
14    /// Stop children started after the failed child in reverse order, then
15    /// restart the failed child and its successors in original order (REQ-017).
16    RestForOne,
17}
18
19/// Sliding-window restart intensity limit (REQ-018).
20#[derive(Debug, Clone)]
21pub struct RestartIntensity {
22    pub max_restarts: u32,
23    pub window: Duration,
24}
25
26impl Default for RestartIntensity {
27    fn default() -> Self {
28        Self {
29            max_restarts: 3,
30            window: Duration::from_secs(5),
31        }
32    }
33}
34
35pub(crate) struct ChildMetadata<R: Reactor = crate::reactor::TokioReactor> {
36    pub(crate) spec: ChildSpec<R>,
37    pub(crate) path: ActorPath,
38    pub(crate) addr: AddrHash,
39    pub(crate) restart_timestamps: VecDeque<Instant>,
40}