pub struct SupervisorBuilder { /* private fields */ }Expand description
Configures and spawns a supervisor.
| Setting | Default |
|---|---|
restart_limit | 5 restarts in 60s |
base_restart_delay | 1s |
max_restart_delay | 30s |
restart_jitter | 0.1 |
dead_tasks_threshold | disabled |
stop_timeout | 5s |
Implementations§
Source§impl SupervisorBuilder
impl SupervisorBuilder
Sourcepub fn with_task(self, name: &str, task: impl SupervisedTask) -> Self
pub fn with_task(self, name: &str, task: impl SupervisedTask) -> Self
Registers a task to start with the supervisor. A later call with the same name replaces the earlier task.
Sourcepub fn with_restart_limit(self, max_restarts: u32, window: Duration) -> Self
pub fn with_restart_limit(self, max_restarts: u32, window: Duration) -> Self
A task that would need more than max_restarts restarts within any
window is declared Dead instead.
max_restarts = 0 disables restarts. The backoff delay doubles with
each restart inside the window, so a task that stays up longer than
window starts again from base_restart_delay.
Sourcepub fn with_unlimited_restarts(self) -> Self
pub fn with_unlimited_restarts(self) -> Self
Never give up restarting a failing task. The window still drives the backoff delay.
Sourcepub fn with_base_restart_delay(self, delay: Duration) -> Self
pub fn with_base_restart_delay(self, delay: Duration) -> Self
Delay before the first restart in a window. Each further restart in the window doubles it.
Sourcepub fn with_max_restart_delay(self, delay: Duration) -> Self
pub fn with_max_restart_delay(self, delay: Duration) -> Self
Upper bound for the restart delay.
Sourcepub fn with_restart_jitter(self, fraction: f64) -> Self
pub fn with_restart_jitter(self, fraction: f64) -> Self
Randomly shortens each restart delay by up to this fraction of itself
(0.0..=1.0), so tasks that failed together do not restart in
lockstep. 0.0 disables it.
Sourcepub fn with_dead_tasks_threshold(self, fraction: f64) -> Self
pub fn with_dead_tasks_threshold(self, fraction: f64) -> Self
Shuts the supervisor down with
TooManyDeadTasks once at
least one task is dead and dead / total >= fraction. Killed tasks
count as dead. fraction is clamped to 0.0..=1.0: 0.0 means “any
dead task”, 1.0 means “every task”.
Sourcepub fn with_stop_timeout(self, timeout: Duration) -> Self
pub fn with_stop_timeout(self, timeout: Duration) -> Self
How long a cancelled run may keep going before its future is dropped. Applies to kill, restart and shutdown.