pub struct ServiceManager<T: ServiceTask + 'static> { /* private fields */ }Expand description
Runs a ServiceTask loop as a service task of an owned task group.
Each run is spawned in a rocketmq.service-manager child of the task group
given at construction, so the owner’s shutdown report and diagnostics
include it. A stopped manager can be started again.
Shutdown waits no longer than the earliest of the deadline passed to
Self::shutdown_until and the deadline installed on the parent task
group by an owner that is shutting down. When neither exists, it uses the
runtime’s default shutdown budget. An interrupting shutdown is the one
exception: it gives the aborted loop at least one second to confirm its
destruction, so with less than a second left it can return up to one
second after that deadline.
Implementations§
Source§impl<T: ServiceTask + 'static> ServiceManager<T>
impl<T: ServiceTask + 'static> ServiceManager<T>
Sourcepub fn new_with_task_group(service: T, parent_task_group: TaskGroup) -> Self
pub fn new_with_task_group(service: T, parent_task_group: TaskGroup) -> Self
Creates a manager whose runs are owned by parent_task_group.
Sourcepub fn new_arc_with_task_group(
service: Arc<T>,
parent_task_group: TaskGroup,
) -> Self
pub fn new_arc_with_task_group( service: Arc<T>, parent_task_group: TaskGroup, ) -> Self
Creates a manager for a shared service whose runs are owned by
parent_task_group.
Sourcepub async fn start(&self) -> RuntimeResult<()>
pub async fn start(&self) -> RuntimeResult<()>
Starts a run of the service loop.
Starting a manager whose loop is still active only logs a warning.
§Errors
Returns an error if the parent task group no longer accepts work.
Sourcepub async fn shutdown(&self) -> RuntimeResult<()>
pub async fn shutdown(&self) -> RuntimeResult<()>
Stops the service and waits for its loop.
The wait ends at the deadline installed on the parent task group, or after the runtime’s default shutdown budget when there is none. A loop still running then is aborted.
§Errors
Currently always succeeds; the result is kept for callers that propagate shutdown failures.
Sourcepub async fn shutdown_with_interrupt(
&self,
interrupt: bool,
) -> RuntimeResult<()>
pub async fn shutdown_with_interrupt( &self, interrupt: bool, ) -> RuntimeResult<()>
Stops the service like Self::shutdown, aborting the loop at once
when interrupt is set.
§Errors
Currently always succeeds; the result is kept for callers that propagate shutdown failures.
Sourcepub async fn shutdown_until(
&self,
deadline: ShutdownDeadline,
) -> RuntimeResult<()>
pub async fn shutdown_until( &self, deadline: ShutdownDeadline, ) -> RuntimeResult<()>
Stops the service and waits for its loop no later than deadline.
§Errors
Currently always succeeds; the result is kept for callers that propagate shutdown failures.
Sourcepub async fn shutdown_with_interrupt_until(
&self,
interrupt: bool,
deadline: ShutdownDeadline,
) -> RuntimeResult<()>
pub async fn shutdown_with_interrupt_until( &self, interrupt: bool, deadline: ShutdownDeadline, ) -> RuntimeResult<()>
Stops the service no later than deadline, aborting the loop at once
when interrupt is set.
An interrupted loop is given at least one second to confirm the abort,
so when less than a second of deadline remains the call can return up
to one second after it.
§Errors
Currently always succeeds; the result is kept for callers that propagate shutdown failures.
Sourcepub fn get_lifecycle_state(&self) -> ServiceTaskState
pub fn get_lifecycle_state(&self) -> ServiceTaskState
Returns the current lifecycle state.
Sourcepub fn last_task_group_shutdown_report(&self) -> Option<ShutdownReport>
pub fn last_task_group_shutdown_report(&self) -> Option<ShutdownReport>
Returns the shutdown report of the task group used by the last stopped run.