pub struct SupervisorBuilder { /* private fields */ }Expand description
Builds a Supervisor instance with configurable parameters.
Configuration methods can be called in any order. Task restart settings
are applied to all tasks uniformly at build() time, regardless of when
with_task() was called.
Implementations§
Source§impl SupervisorBuilder
impl SupervisorBuilder
Sourcepub fn with_task(self, name: &str, task: impl SupervisedTask + Clone) -> Self
pub fn with_task(self, name: &str, task: impl SupervisedTask + Clone) -> Self
Adds a task to the supervisor with the specified name.
Task restart configuration is applied at build() time, so the
order of with_task() vs configuration methods does not matter.
Sourcepub fn with_max_backoff_exponent(self, exponent: u32) -> Self
pub fn with_max_backoff_exponent(self, exponent: u32) -> Self
Sets the maximum exponent used in exponential backoff.
The restart delay is calculated as base_restart_delay * 2^min(attempt, max_backoff_exponent).
For example, with a base delay of 1s and exponent cap of 5, the maximum delay is 32s.
Sourcepub fn with_health_check_interval(self, interval: Duration) -> Self
pub fn with_health_check_interval(self, interval: Duration) -> Self
Sets the interval between health checks.
Sourcepub fn with_max_restart_attempts(self, attempts: u32) -> Self
pub fn with_max_restart_attempts(self, attempts: u32) -> Self
Sets the maximum number of restart attempts for tasks.
Sourcepub fn with_unlimited_restarts(self) -> Self
pub fn with_unlimited_restarts(self) -> Self
Disables the restart limit, allowing tasks to restart indefinitely.
Sourcepub fn with_base_restart_delay(self, delay: Duration) -> Self
pub fn with_base_restart_delay(self, delay: Duration) -> Self
Sets the base delay for task restarts, used in exponential backoff.
Sourcepub fn with_task_being_stable_after(self, delay: Duration) -> Self
pub fn with_task_being_stable_after(self, delay: Duration) -> Self
Sets the delay after which a task is considered stable and healthy. When a task is considered stable, its restarts are reset to zero.
Sourcepub fn with_dead_tasks_threshold(
self,
threshold_percentage: Option<f64>,
) -> Self
pub fn with_dead_tasks_threshold( self, threshold_percentage: Option<f64>, ) -> Self
Sets the threshold for the percentage of dead tasks that will trigger a supervisor shutdown.
The threshold_percentage should be a value between 0.0 (0%) and 1.0 (100%).
If the percentage of dead tasks exceeds this value, the supervisor will shut down
and return an error.
Sourcepub fn build(self) -> Supervisor
pub fn build(self) -> Supervisor
Constructs the Supervisor with the configured settings.
Applies restart configuration (max attempts, base delay, backoff exponent) to all registered tasks.