pub struct Supervisor { /* private fields */ }Expand description
Supervises a set of workers.
§Workers
All workers are defined through implementation of the Supervisable trait, which provides the logic for both
creating the underlying worker future that is spawned, as well as other metadata, such as the worker’s name, how the
worker should be shutdown, and so on.
Supervisors also (indirectly) implement the Supervisable trait, allowing them to be supervised by other
supervisors in order to construct supervision trees.
§Instrumentation
Supervisors automatically create their own allocation group
([TrackingAllocator][memory_accounting::allocator::TrackingAllocator]), which is used to track both the memory usage of the
supervisor itself and its children. Additionally, individual worker processes are wrapped in a dedicated
tracing::Span to allow tracing the casual relationship between arbitrary code and the worker executing it.
§Restart Strategies
As the main purpose of a supervisor, restart behavior is fully configurable. A number of restart strategies are available, which generally relate to the purpose of the supervisor: whether the workers being managed are independent or interdependent.
All restart strategies are configured through RestartStrategy, which has more information on the available
strategies and configuration settings.
Implementations§
Source§impl Supervisor
impl Supervisor
Sourcepub fn new<S: AsRef<str>>(supervisor_id: S) -> Result<Self, SupervisorError>
pub fn new<S: AsRef<str>>(supervisor_id: S) -> Result<Self, SupervisorError>
Creates an empty Supervisor with the default restart strategy.
Sourcepub fn with_restart_strategy(self, strategy: RestartStrategy) -> Self
pub fn with_restart_strategy(self, strategy: RestartStrategy) -> Self
Sets the restart strategy for the supervisor.
Sourcepub fn add_worker<T: Into<ChildSpecification>>(&mut self, process: T)
pub fn add_worker<T: Into<ChildSpecification>>(&mut self, process: T)
Adds a worker to the supervisor.
A worker can be anything that implements the Supervisable trait. A Supervisor can also be added as a
worker and managed in a nested fashion, known as a supervision tree.
Sourcepub async fn run(&mut self) -> Result<(), SupervisorError>
pub async fn run(&mut self) -> Result<(), SupervisorError>
Runs the supervisor forever.
§Errors
If the supervisor exceeds its restart limits, or fails to initialize a child process, an error is returned.
Sourcepub async fn run_with_shutdown<F: Future + Send + 'static>(
&mut self,
shutdown: F,
) -> Result<(), SupervisorError>
pub async fn run_with_shutdown<F: Future + Send + 'static>( &mut self, shutdown: F, ) -> Result<(), SupervisorError>
Runs the supervisor until shutdown is triggered.
When shutdown resolves, the supervisor will shutdown all child processes according to their shutdown strategy,
and then return.
§Errors
If the supervisor exceeds its restart limits, or fails to initialize a child process, an error is returned.
Auto Trait Implementations§
impl Freeze for Supervisor
impl !RefUnwindSafe for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl !UnwindSafe for Supervisor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked wrapper. Read more