pub struct ResumableWorker<L> { /* private fields */ }Expand description
A worker that keeps the state of its work across restarts.
Most workers build their work again each time they start. A ResumableWorker keeps its Resumable state instead,
so that each start continues from where the previous one stopped: a restart resumes rather than resets. This holds
even after a panic, so a state that a panic left inconsistent can fail again until the restart limit of the owner
passes the failure up the supervision tree.
Create one with new, or with start_early for work that has to start before any
supervisor runs. The worker isn’t Clone: add it to one owner only.
§Starting early
start_early runs the work at once in a plain task. The task isn’t a process: it has no
process identifier, scope, or dataspace, so the work can’t spawn children or assert anything, and it isn’t part of
any supervision tree. It runs in the span and resource group of the caller.
When the worker first starts under supervision, it signals the early task to stop, waits for run to return at a
point that loses no work, and then continues with the same state as a supervised process. If run ended before
that, the first start ends with its result. If it panicked, the first start panics again. The shutdown strategy of
the worker bounds the wait.
Dropping the worker before it first starts cancels the task.
§State
The same state is used before supervision and by each instance of the worker, so it MUST NOT hold anything
bound to a process, such as a Scope, a ScopeGuard, or a
SupervisorHandle. Set those up in each call to run instead.
Timers and connections stay bound to the Tokio runtime that created them. Don’t run the worker on a runtime that is
replaced when its owner restarts, such as the runtime of a supervisor with a
dedicated runtime, unless run builds them again.
Implementations§
Source§impl<L: Resumable> ResumableWorker<L>
impl<L: Resumable> ResumableWorker<L>
Sourcepub fn new<N: Into<String>>(name: N, state: L) -> Self
pub fn new<N: Into<String>>(name: N, state: L) -> Self
Creates a worker named name that runs state each time it starts.
Sourcepub fn start_early<N: Into<String>>(name: N, state: L) -> Self
pub fn start_early<N: Into<String>>(name: N, state: L) -> Self
Starts running state now, in a task named name, and returns the worker that takes it over when it first
starts.
See Starting early.
§Panics
Panics if called outside of a Tokio runtime.
Trait Implementations§
Source§impl<L> Debug for ResumableWorker<L>
impl<L> Debug for ResumableWorker<L>
Source§impl<L: Resumable> Supervisable for ResumableWorker<L>
impl<L: Resumable> Supervisable for ResumableWorker<L>
Source§fn shutdown_strategy(&self) -> ShutdownStrategy
fn shutdown_strategy(&self) -> ShutdownStrategy
Source§fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn wants_shutdown_signal(&self) -> bool
fn wants_shutdown_signal(&self) -> bool
Source§fn can_restart(&self) -> bool
fn can_restart(&self) -> bool
Auto Trait Implementations§
impl<L> !Freeze for ResumableWorker<L>
impl<L> !RefUnwindSafe for ResumableWorker<L>
impl<L> Send for ResumableWorker<L>where
L: Send,
impl<L> Sync for ResumableWorker<L>where
L: Send,
impl<L> Unpin for ResumableWorker<L>
impl<L> UnsafeUnpin for ResumableWorker<L>
impl<L> !UnwindSafe for ResumableWorker<L>
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_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more