Skip to main content

SupervisorBuilder

Struct SupervisorBuilder 

Source
pub struct SupervisorBuilder { /* private fields */ }
Expand description

Builder for constructing a Supervisor.

Use this when you need to customize runtime config, subscribers, or optional feature-backed components before starting the supervisor.

The produced supervisor is not started yet. Calling build only creates the runtime graph and stores the pieces that will be used later by Supervisor::run or Supervisor::serve.

§Also

Implementations§

Source§

impl SupervisorBuilder

Source

pub fn new(cfg: SupervisorConfig) -> Self

Creates a new builder with the given runtime configuration.

Start from SupervisorConfig::default and adjust single values with the with_* setters below.

Source

pub fn with_grace(self, grace: Duration) -> Self

Builder: sets the graceful-shutdown wait time.

During shutdown the supervisor waits up to grace for tasks to stop. Duration::ZERO means no graceful wait.

Source

pub fn with_subscriber_shutdown_timeout(self, timeout: Duration) -> Self

Sets the shared timeout for draining subscriber queues during shutdown.

The default is five seconds. Duration::ZERO closes the queues and aborts their async workers without waiting for queued events. A callback already running on Tokio’s blocking pool cannot be aborted and may finish later. Tokio runtime shutdown may still wait for that running blocking callback. Reaching this best-effort cleanup timeout does not produce a RuntimeError.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Builder: sets the default timeout for one task attempt.

A zero duration means no timeout. Tasks created outside SupervisorConfig::task_spec keep their own timeout.

Source

pub fn with_max_retries(self, max_retries: u32) -> Self

Builder: sets the default failure-retry limit.

The default is unlimited retries. Call this only when you want a limit.

Use RestartPolicy::Never to stop a task after its first failure.

Source

pub fn with_max_concurrent(self, max_concurrent: usize) -> Self

Builder: sets the global limit for concurrently running task attempts.

The default is unlimited concurrency. Call this only when you want a limit.

With zero permits no task could ever run.

Source

pub fn with_bus_capacity(self, bus_capacity: usize) -> Self

Builder: sets the event bus capacity.

The effective capacity is at least 1. Slow subscribers that fall behind by more than this may skip older events.

Source

pub fn with_restart(self, restart: RestartPolicy) -> Self

Builder: sets the default restart policy for tasks created through SupervisorConfig::task_spec.

Restart controls whether a task runs again after it exits.

Source

pub fn with_backoff(self, backoff: BackoffPolicy) -> Self

Builder: sets the default backoff policy for retryable failures.

Backoff controls the delay before a failed attempt restarts.

Source

pub fn with_subscribers(self, subscribers: Vec<Arc<dyn Subscribe>>) -> Self

Sets event subscribers for runtime observability.

Each subscriber gets its own bounded queue and worker task. The workers are created during build, and events are delivered after the supervisor starts its runtime listener.

Passing a new list replaces any subscribers previously set on this builder.

Source

pub fn with_controller(self, config: ControllerConfig) -> Self

Available on crate feature controller only.

Enables the controller with the given configuration.

The controller adds slot-based task admission on top of the core supervisor. It can queue, replace, or drop submissions depending on the configured slot policy.

Available only with the controller feature.

Source

pub fn build(self) -> Arc<Supervisor>

Builds the supervisor.

This consumes the builder and creates all runtime components.

The supervisor is returned in a stopped state. Task execution starts when the caller runs or serves the supervisor.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more