pub struct Worker { /* private fields */ }Expand description
A worker polls on a certain task queue
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(
config: WorkerConfig,
sticky_queue_name: Option<String>,
client: Arc<dyn WorkerClient>,
telem_instance: Option<&TelemetryInstance>,
heartbeat_fn: Option<Arc<OnceLock<Box<dyn Fn() -> Option<WorkerHeartbeat> + Send + Sync>>>>,
) -> Self
pub fn new( config: WorkerConfig, sticky_queue_name: Option<String>, client: Arc<dyn WorkerClient>, telem_instance: Option<&TelemetryInstance>, heartbeat_fn: Option<Arc<OnceLock<Box<dyn Fn() -> Option<WorkerHeartbeat> + Send + Sync>>>>, ) -> Self
Creates a new Worker from a WorkerClient instance with real task pollers and optional telemetry.
This is a convenience constructor that logs initialization and delegates to Worker::new_with_pollers() using [TaskPollers::Real].
Sourcepub fn replace_client<CT>(&self, new_client: CT)where
CT: Into<AnyClient>,
pub fn replace_client<CT>(&self, new_client: CT)where
CT: Into<AnyClient>,
Replace client. For eager workflow purposes, this new client will now apply to future eager start requests and the older client will not.
Sourcepub async fn cached_workflows(&self) -> usize
pub async fn cached_workflows(&self) -> usize
Returns number of currently cached workflows
Trait Implementations§
Source§impl Worker for Worker
impl Worker for Worker
Source§fn initiate_shutdown(&self)
fn initiate_shutdown(&self)
Begins the shutdown process, tells pollers they should stop. Is idempotent.
Source§fn validate<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), WorkerValidationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn validate<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), WorkerValidationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Validate that the worker can properly connect to server, plus any other validation that
needs to be done asynchronously. Lang SDKs should call this function once before calling
any others.
Source§fn poll_workflow_activation<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<WorkflowActivation, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn poll_workflow_activation<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<WorkflowActivation, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Ask the worker for some work, returning a WorkflowActivation. It is then the language
SDK’s responsibility to call the appropriate workflow code with the provided inputs. Blocks
indefinitely until such work is available or Worker::shutdown is called. Read more
Source§fn poll_activity_task<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ActivityTask, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn poll_activity_task<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ActivityTask, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Ask the worker for some work, returning an ActivityTask. It is then the language SDK’s
responsibility to call the appropriate activity code with the provided inputs. Blocks
indefinitely until such work is available or Worker::shutdown is called. Read more
Source§fn poll_nexus_task<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<NexusTask, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn poll_nexus_task<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<NexusTask, PollError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Ask the worker for some nexus related work. It is then the language SDK’s
responsibility to call the appropriate nexus operation handler code with the provided
inputs. Blocks indefinitely until such work is available or Worker::shutdown is called. Read more
Source§fn complete_workflow_activation<'life0, 'async_trait>(
&'life0 self,
completion: WorkflowActivationCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteWfError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete_workflow_activation<'life0, 'async_trait>(
&'life0 self,
completion: WorkflowActivationCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteWfError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Tell the worker that a workflow activation has completed. May (and should) be freely called
concurrently. The future may take some time to resolve, as fetching more events might be
necessary for completion to… complete - thus SDK implementers should make sure they do
not serialize completions.
Source§fn complete_activity_task<'life0, 'async_trait>(
&'life0 self,
completion: ActivityTaskCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteActivityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete_activity_task<'life0, 'async_trait>(
&'life0 self,
completion: ActivityTaskCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteActivityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Tell the worker that an activity has finished executing. May (and should) be freely called
concurrently.
Source§fn complete_nexus_task<'life0, 'async_trait>(
&'life0 self,
completion: NexusTaskCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteNexusError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete_nexus_task<'life0, 'async_trait>(
&'life0 self,
completion: NexusTaskCompletion,
) -> Pin<Box<dyn Future<Output = Result<(), CompleteNexusError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Tell the worker that a nexus task has completed. May (and should) be freely called
concurrently.
Source§fn record_activity_heartbeat(&self, details: ActivityHeartbeat)
fn record_activity_heartbeat(&self, details: ActivityHeartbeat)
Notify the Temporal service that an activity is still alive. Long running activities that
take longer than
activity_heartbeat_timeout to finish must call this function in order to
report progress, otherwise the activity will timeout and a new attempt will be scheduled. Read moreSource§fn request_workflow_eviction(&self, run_id: &str)
fn request_workflow_eviction(&self, run_id: &str)
Request that a workflow be evicted by its run id. This will generate a workflow activation
with the eviction job inside it to be eventually returned by
Worker::poll_workflow_activation. If the workflow had any existing outstanding activations,
such activations are invalidated and subsequent completions of them will do nothing and log
a warning.
Source§fn get_config(&self) -> &WorkerConfig
fn get_config(&self) -> &WorkerConfig
Return this worker’s config
Source§fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Initiates async shutdown procedure, eventually ceases all polling of the server and shuts
down this worker. Worker::poll_workflow_activation and Worker::poll_activity_task should
be called until both return a
ShutDown error to ensure that all outstanding work is
complete. This means that the lang sdk will need to call
Worker::complete_workflow_activation and Worker::complete_activity_task for those
workflows & activities until they are done. At that point, the lang SDK can end the process,
or drop the Worker instance via Worker::finalize_shutdown, which will close the
connection and free resources. If you have set WorkerConfig::no_remote_activities, you may
skip calling Worker::poll_activity_task. Read moreSource§fn finalize_shutdown<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
fn finalize_shutdown<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
Completes shutdown and frees all resources. You should avoid simply dropping workers, as
this does not allow async tasks to report any panics that may have occurred cleanly. Read more
Auto Trait Implementations§
impl !Freeze for Worker
impl !RefUnwindSafe for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
Wrap the input message
T in a tonic::Request