Skip to main content

SupervisorBuilder

Struct SupervisorBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new builder with default configuration values.

Source

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.

Source

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.

Source

pub fn with_health_check_interval(self, interval: Duration) -> Self

Sets the interval between health checks.

Source

pub fn with_max_restart_attempts(self, attempts: u32) -> Self

Sets the maximum number of restart attempts for tasks.

Source

pub fn with_unlimited_restarts(self) -> Self

Disables the restart limit, allowing tasks to restart indefinitely.

Source

pub fn with_base_restart_delay(self, delay: Duration) -> Self

Sets the base delay for task restarts, used in exponential backoff.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for SupervisorBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.