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 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: Send + Sync + 'static>(&self, data: T)
pub fn emit<T: Send + Sync + 'static>(&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 cancel_task(&self, context: &TaskContext) -> Result<(), TaskStateError>
Available on crate feature task-context only.
pub fn cancel_task(&self, context: &TaskContext) -> Result<(), TaskStateError>
task-context only.Cancel a specific task, if it’s tracked.
Sourcepub fn get_task(&self, task_id: &str) -> Result<TaskContext, TaskStateError>
Available on crate feature task-context only.
pub fn get_task(&self, task_id: &str) -> Result<TaskContext, TaskStateError>
task-context only.Get the task context for a task attached to a worker
Sourcepub fn cleanup(&self) -> Result<(), TaskStateError>
Available on crate feature task-context only.
pub fn cleanup(&self) -> Result<(), TaskStateError>
task-context only.Remove any completed tasks
Sourcepub fn tasks(&self) -> Result<Vec<TaskContext>, TaskStateError>
Available on crate feature task-context only.
pub fn tasks(&self) -> Result<Vec<TaskContext>, TaskStateError>
task-context only.Get the context of each running task
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.