Skip to main content

Worker

Struct Worker 

Source
pub struct Worker { /* private fields */ }
Expand description

A worker polls on a certain task queue

Implementations§

Source§

impl Worker

Source

pub async fn validate(&self) -> Result<NamespaceInfo, WorkerValidationError>

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

pub fn replace_client(&self, new_connection: Connection) -> Result<(), Error>

Replace client.

For eager workflow purposes, this new client will now apply to future eager start requests and the older client will not. Note, if this registration fails, the worker heartbeat will also not be registered.

For worker heartbeat, this will remove an existing shared worker if it is the last worker of the old client and create a new nexus worker if it’s the first client of the namespace on the new client.

Source

pub async fn shutdown(&self)

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::task_types to exclude WorkerTaskTypes::activity_only(), you may skip calling Worker::poll_activity_task.

Lang implementations should use Worker::initiate_shutdown followed by Worker::finalize_shutdown.

Source

pub async fn finalize_shutdown(self)

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.

This should be called only after Worker::shutdown has resolved and/or both polling functions have returned ShutDown errors.

Source

pub async fn cached_workflows(&self) -> usize

Returns number of currently cached workflows

Source

pub async fn poll_activity_task(&self) -> Result<ActivityTask, PollError>

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.

Do not call poll concurrently. It handles polling the server concurrently internally.

Local activities are returned first before polling the server if there are any.

Source

pub 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.

The first heartbeat request will be sent immediately, subsequent rapid calls to this function will result in heartbeat requests being aggregated and the last one received during the aggregation period will be sent to the server, where that period is defined as half the heartbeat timeout.

Unlike Java/Go SDKs we do not return cancellation status as part of heartbeat response and instead send it as a separate activity task to the lang, decoupling heartbeat and cancellation processing.

For now activity still need to send heartbeats if they want to receive cancellation requests. In the future we will change this and will dispatch cancellations more proactively. Note that this function does not block on the server call and returns immediately. Underlying validation errors are swallowed and logged, this has been agreed to be optimal behavior for the user as we don’t want to break activity execution due to badly configured heartbeat options.

Source

pub async fn complete_activity_task( &self, completion: ActivityTaskCompletion, ) -> Result<(), CompleteActivityError>

Tell the worker that an activity has finished executing. May (and should) be freely called concurrently.

Source

pub async fn poll_workflow_activation( &self, ) -> Result<WorkflowActivation, PollError>

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.

It is important to understand that all activations must be responded to. There can only be one outstanding activation for a particular run of a workflow at any time. If an activation is not responded to, it will cause that workflow to become stuck forever.

See WorkflowActivation for more details on the expected behavior of lang w.r.t activation & job processing.

Do not call poll concurrently. It handles polling the server concurrently internally.

Source

pub async fn complete_workflow_activation( &self, completion: WorkflowActivationCompletion, ) -> Result<(), CompleteWfError>

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

pub async fn poll_nexus_task(&self) -> Result<NexusTask, PollError>

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.

All tasks must be responded to for shutdown to complete.

Do not call poll concurrently. It handles polling the server concurrently internally.

Source

pub async fn complete_nexus_task( &self, completion: NexusTaskCompletion, ) -> Result<(), CompleteNexusError>

Tell the worker that a nexus task has completed. May (and should) be freely called concurrently.

Source

pub 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

pub fn get_config(&self) -> &WorkerConfig

Return this worker’s config

Source

pub fn get_namespace_capabilities(&self) -> &NamespaceCapabilities

Returns the namespace capabilities discovered during Worker::validate.

Source

pub fn initiate_shutdown(&self)

Initiate shutdown, including spawning the ShutdownWorker RPC so the server can complete in-flight polls. The RPC runs in a background task and is awaited in Worker::shutdown.

You can then wait on shutdown or Worker::finalize_shutdown.

Source

pub fn worker_instance_key(&self) -> Uuid

Unique identifier for this worker instance. This must be stable across the worker’s lifetime and unique per instance.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,