pub struct Worker { /* private fields */ }Expand description
A worker that can poll for and respond to workflow tasks by using temporalio_macros::workflow, and activity tasks by using activities defined with temporalio_macros::activities.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(
runtime: &CoreRuntime,
client: Client,
options: WorkerOptions,
) -> Result<Self, Box<dyn Error>>
pub fn new( runtime: &CoreRuntime, client: Client, options: WorkerOptions, ) -> Result<Self, Box<dyn Error>>
Create a new worker from an existing connection, and options.
Sourcepub fn task_queue(&self) -> &str
pub fn task_queue(&self) -> &str
Returns the task queue name this worker polls on
Sourcepub fn shutdown_handle(&self) -> impl Fn() + use<>
pub fn shutdown_handle(&self) -> impl Fn() + use<>
Return a handle that can be used to initiate shutdown. This is useful because Worker::run takes self mutably, so you may want to obtain a handle for shutting down before running.
Sourcepub fn register_activities<AI: ActivityImplementer>(
&mut self,
instance: AI,
) -> &mut Self
pub fn register_activities<AI: ActivityImplementer>( &mut self, instance: AI, ) -> &mut Self
Registers all activities on an activity implementer.
Sourcepub fn register_activity<AD>(
&mut self,
instance: Arc<AD::Implementer>,
) -> &mut Self
pub fn register_activity<AD>( &mut self, instance: Arc<AD::Implementer>, ) -> &mut Self
Registers a specific activitiy.
Sourcepub fn register_workflow<WI: WorkflowImplementer>(&mut self) -> &mut Self
pub fn register_workflow<WI: WorkflowImplementer>(&mut self) -> &mut Self
Registers all workflows on a workflow implementer.
Sourcepub fn register_workflow_with_factory<W, F>(&mut self, factory: F) -> &mut Self
pub fn register_workflow_with_factory<W, F>(&mut self, factory: F) -> &mut Self
Register a workflow with a custom factory for instance creation.
See WorkerOptionsBuilder::register_workflow_with_factory for more.
Sourcepub async fn run(&mut self) -> Result<(), Error>
pub async fn run(&mut self) -> Result<(), Error>
Runs the worker. Eventually resolves after the worker has been explicitly shut down, or may return early with an error in the event of some unresolvable problem.
Sourcepub fn set_worker_interceptor(
&mut self,
interceptor: impl WorkerInterceptor + 'static,
)
pub fn set_worker_interceptor( &mut self, interceptor: impl WorkerInterceptor + 'static, )
Set a WorkerInterceptor
Sourcepub fn with_new_core_worker(&mut self, new_core_worker: Arc<CoreWorker>)
pub fn with_new_core_worker(&mut self, new_core_worker: Arc<CoreWorker>)
Turns this rust worker into a new worker with all the same workflows and activities registered, but with a new underlying core worker. Can be used to swap the worker for a replay worker, change task queues, etc.
Sourcepub fn cached_workflows(&self) -> usize
pub fn cached_workflows(&self) -> usize
Returns number of currently cached workflows as understood by the SDK. Importantly, this is not the same as understood by core, though they should always be in sync.
Sourcepub fn worker_instance_key(&self) -> Uuid
pub fn worker_instance_key(&self) -> Uuid
Returns the instance key for this worker, used for worker heartbeating.
Auto Trait Implementations§
impl !Freeze for Worker
impl !RefUnwindSafe for Worker
impl !Send for Worker
impl !Sync for Worker
impl Unpin for Worker
impl UnsafeUnpin for Worker
impl !UnwindSafe for Worker
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§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::Request