nv_runtime/shutdown.rs
1//! Shutdown and restart policy types.
2
3use nv_core::Duration;
4
5/// Controls automatic feed restart behavior after failures.
6///
7/// # Restart semantics
8///
9/// - `restart_on == Never` — never restart, regardless of other fields.
10/// - `max_restarts == 0` — never restart, regardless of `restart_window`.
11/// - `max_restarts > 0` — allow up to this many restarts within
12/// `restart_window`. If the feed stays alive longer than the window
13/// the counter resets, allowing further restarts.
14#[derive(Debug, Clone)]
15pub struct RestartPolicy {
16 /// Maximum number of restarts before giving up.
17 ///
18 /// `0` means never restart — the `restart_window` cannot override this.
19 pub max_restarts: u32,
20 /// Reset the restart counter after this much consecutive uptime.
21 pub restart_window: Duration,
22 /// Delay before restarting.
23 pub restart_delay: Duration,
24 /// What triggers an automatic restart.
25 pub restart_on: RestartTrigger,
26}
27
28impl Default for RestartPolicy {
29 fn default() -> Self {
30 Self {
31 max_restarts: 5,
32 restart_window: Duration::from_secs(300),
33 restart_delay: Duration::from_secs(2),
34 restart_on: RestartTrigger::SourceOrStagePanic,
35 }
36 }
37}
38
39/// What triggers an automatic feed restart.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum RestartTrigger {
42 /// Restart on source failure only.
43 SourceFailure,
44 /// Restart on source failure or stage panic.
45 SourceOrStagePanic,
46 /// Never restart automatically.
47 Never,
48}