pub struct WorkerContext { /* private fields */ }Expand description
Utility for managing a worker’s context
A worker context is created for each worker thread and is responsible for managing the worker’s state, task tracking, and event handling.
Tip: All fields are wrapped inside Arc so it should be cheap to clone
Implementations§
Source§impl WorkerContext
impl WorkerContext
Sourcepub fn new(name: &str) -> WorkerContext
pub fn new(name: &str) -> WorkerContext
Create a new worker context
Sourcepub fn start(&mut self) -> Result<(), WorkerError>
pub fn start(&mut self) -> Result<(), WorkerError>
Start running the worker
Sourcepub fn pause(&self) -> Result<(), WorkerError>
pub fn pause(&self) -> Result<(), WorkerError>
Pauses a worker, preventing any new jobs from being polled
Sourcepub fn resume(&self) -> Result<(), WorkerError>
pub fn resume(&self) -> Result<(), WorkerError>
Resume a worker that is paused
Sourcepub fn stop(&self) -> Result<(), WorkerError>
pub fn stop(&self) -> Result<(), WorkerError>
Calling this function triggers shutting down the worker while waiting for any tasks to complete
Sourcepub fn get_service(&self) -> &str
pub fn get_service(&self) -> &str
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Checks whether the worker is running
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Checks whether the worker is pending
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Checks whether the worker has been stopped
Sourcepub fn is_terminated(&self) -> bool
pub fn is_terminated(&self) -> bool
Checks whether the worker is terminated
Sourcepub fn task_count(&self) -> usize
pub fn task_count(&self) -> usize
Checks the current futures in the worker domain
This include futures spawned via worker.track
Sourcepub fn has_pending_tasks(&self) -> bool
pub fn has_pending_tasks(&self) -> bool
Checks whether the worker has pending tasks
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Is the shutdown token called
Sourcepub fn emit<T>(&self, data: T)
pub fn emit<T>(&self, data: T)
Emits a Event::Custom to the worker’s event handler
Sourcepub fn heartbeat(&self, cx: &mut Context<'_>)
pub fn heartbeat(&self, cx: &mut Context<'_>)
Calls a method to signify a heartbeat with the worker
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the amount of time elapsed since this worker started.
Sourcepub fn restarts(&self) -> usize
pub fn restarts(&self) -> usize
Returns the number of times the worker has been restated:
See also Monitor::should_restart
Sourcepub fn kill(&mut self) -> Result<(), WorkerError>
pub fn kill(&mut self) -> Result<(), WorkerError>
This forces a shutting down worker to exit.
Trait Implementations§
Source§impl Clone for WorkerContext
impl Clone for WorkerContext
Source§fn clone(&self) -> WorkerContext
fn clone(&self) -> WorkerContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkerContext
impl Debug for WorkerContext
Source§impl Drop for WorkerContext
impl Drop for WorkerContext
Source§impl From<&WorkerContext> for WorkerContext
impl From<&WorkerContext> for WorkerContext
Source§fn from(context: &WorkerContext) -> WorkerContext
fn from(context: &WorkerContext) -> WorkerContext
Source§impl From<&str> for WorkerContext
impl From<&str> for WorkerContext
Source§fn from(name: &str) -> WorkerContext
fn from(name: &str) -> WorkerContext
Source§impl From<String> for WorkerContext
impl From<String> for WorkerContext
Source§fn from(name: String) -> WorkerContext
fn from(name: String) -> WorkerContext
Source§impl<Args> FromRequest<Task<Args>> for WorkerContextwhere
Args: Sync,
impl<Args> FromRequest<Task<Args>> for WorkerContextwhere
Args: Sync,
Source§type Error = MissingDataError
type Error = MissingDataError
Source§async fn from_request(
task: &Task<Args>,
) -> Result<WorkerContext, <WorkerContext as FromRequest<Task<Args>>>::Error>
async fn from_request( task: &Task<Args>, ) -> Result<WorkerContext, <WorkerContext as FromRequest<Task<Args>>>::Error>
Auto Trait Implementations§
impl !RefUnwindSafe for WorkerContext
impl !UnwindSafe for WorkerContext
impl Forget for WorkerContext
impl Freeze for WorkerContext
impl Move for WorkerContext
impl Send for WorkerContext
impl Sync for WorkerContext
impl Unpin for WorkerContext
impl UnsafeUnpin for WorkerContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more