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
Supervisor- runtime facade produced by this builderSupervisorConfig- runtime defaults and limitsSubscribe- event subscriber trait
Implementations§
Source§impl SupervisorBuilder
impl SupervisorBuilder
Sourcepub fn new(cfg: SupervisorConfig) -> Self
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.
Sourcepub fn with_grace(self, grace: Duration) -> Self
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.
Sourcepub fn with_subscriber_shutdown_timeout(self, timeout: Duration) -> Self
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.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
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.
Sourcepub fn with_max_retries(self, max_retries: u32) -> Self
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.
Sourcepub fn with_max_concurrent(self, max_concurrent: usize) -> Self
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.
Sourcepub fn with_bus_capacity(self, bus_capacity: usize) -> Self
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.
Sourcepub fn with_restart(self, restart: RestartPolicy) -> Self
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.
Sourcepub fn with_backoff(self, backoff: BackoffPolicy) -> Self
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.
Sourcepub fn with_subscribers(self, subscribers: Vec<Arc<dyn Subscribe>>) -> Self
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.
Sourcepub fn with_controller(self, config: ControllerConfig) -> Self
Available on crate feature controller only.
pub fn with_controller(self, config: ControllerConfig) -> Self
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.
Sourcepub fn build(self) -> Arc<Supervisor> ⓘ
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.