pub struct Worker { /* private fields */ }Expand description
Configured Rust worker with typed activity handlers.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn builder(config: WorkerConfig) -> WorkerBuilder
pub fn builder(config: WorkerConfig) -> WorkerBuilder
Starts a new builder for the supplied config.
Sourcepub fn activity_types(&self) -> &[String]
pub fn activity_types(&self) -> &[String]
Returns the activity types this worker registers with the engine.
Sourcepub fn available_handlers(&self) -> &BTreeSet<String>
pub fn available_handlers(&self) -> &BTreeSet<String>
Returns the handler-name set used for registration validation.
Sourcepub async fn run(self) -> Result<(), WorkerError>
pub async fn run(self) -> Result<(), WorkerError>
Connects to the configured endpoint, registers activities, and serves indefinitely.
Registration completes only when the server’s RegisterAck — the
guaranteed first response frame — arrives; the worker serves nothing
before it. Session establishment goes through the bounded-backoff
reconnect machinery configured in WorkerConfig::reconnect, and
retryable mid-run transport drops — including clean server-side
stream closes — re-establish through the same machinery: the worker
re-registers its activity types, re-reports every unacknowledged
activity result (cleared only by the server’s per-result ResultAck
frames), and resumes serving. A server-announced drain reconnects
after the schedule’s initial backoff without consuming drop budget.
Deterministic PermissionDenied / Unauthenticated denials surface
after exactly one attempt. Without a shutdown signal the run ends
only on a non-retryable error or drop-budget exhaustion; see
crate::config::ReconnectConfig for the budget-reset semantics.
§Errors
Returns WorkerError for connection, registration, dispatch, heartbeat, or report failures.
Sourcepub async fn run_until<Shutdown>(
self,
shutdown: Shutdown,
) -> Result<(), WorkerError>
pub async fn run_until<Shutdown>( self, shutdown: Shutdown, ) -> Result<(), WorkerError>
Connects to the configured endpoint, registers activities, and serves until shutdown fires.
Establishment and mid-run reconnect behaviour match Worker::run.
On shutdown, no new tasks are pulled, in-flight activity contexts are
marked cancelled, and all in-flight activities are drained before this
returns; shutdown signalled during a reconnect or backoff wins
promptly without waiting out the backoff delay.
§Errors
Returns WorkerError for connection, registration, dispatch, heartbeat, or report failures.
Sourcepub async fn run_with_connector_until<S, F, Fut, Shutdown>(
self,
connect: F,
shutdown: Shutdown,
) -> Result<(), WorkerError>where
S: WorkerSession,
F: FnMut() -> Fut,
Fut: Future<Output = Result<S, WorkerError>>,
Shutdown: Future<Output = ()> + Send,
pub async fn run_with_connector_until<S, F, Fut, Shutdown>(
self,
connect: F,
shutdown: Shutdown,
) -> Result<(), WorkerError>where
S: WorkerSession,
F: FnMut() -> Fut,
Fut: Future<Output = Result<S, WorkerError>>,
Shutdown: Future<Output = ()> + Send,
Runs the reconnect-aware serve loop over an injected session factory.
Session establishment goes through
reconnect_with_backoff:
transient failures retry up to the configured reconnect.max_attempts
with bounded exponential backoff, while PermissionDenied /
Unauthenticated denials surface after exactly one attempt. When an
established session drops retryably mid-run — a retryable transport
failure or an unannounced clean server-side stream close, both count —
the worker drains in-flight activities into the unacked tracker, backs
off, reconnects through the same machinery (re-registering its
activity types), re-reports every still-unacknowledged result (the
shutdown signal can interrupt that replay; tracked results survive),
and resumes serving. Server ResultAck frames clear tracker entries
mid-session, so the steady-state replay backlog is empty.
Mid-run drops share one cumulative budget of reconnect.max_attempts,
matching the Python and TypeScript workers, and the budget resets to
zero once a session proves healthy: it served at least one task, or it
stayed connected longer than reconnect.max_backoff (measured
monotonically from successful registration to the moment the stream
ended or dropped — post-drop draining of in-flight activities never
extends it). A server-announced drain is unbudgeted: the worker
finishes in-flight work and redials after reconnect.initial_backoff;
the drain classification latches for the session, so even an abrupt
end after the drain frame stays drain-class. See
crate::config::ReconnectConfig. The run therefore ends only on
shutdown, a non-retryable error, or budget exhaustion — never merely
because the server closed or drained the stream. At most one session
is alive at a time, and a shutdown signalled during a reconnect or
backoff wins promptly (returning Ok when the pending drop was a
drain or clean close, and the pending error when it was a failure).
§Errors
Returns WorkerError when establishment attempts are exhausted or
denied, when a non-retryable error occurs mid-run, when the mid-run
drop budget is exhausted (WorkerError::CleanCloseExhausted when
the exhausting drops were clean closes), or when shutdown interrupts
an unrecovered error drop.
Sourcepub async fn run_with_session<S>(self, session: S) -> Result<S, WorkerError>where
S: WorkerSession,
pub async fn run_with_session<S>(self, session: S) -> Result<S, WorkerError>where
S: WorkerSession,
Test seam that handshakes, registers, and serves an injected session until its stream ends.
§Errors
Returns WorkerError for registration, dispatch, heartbeat, or report failures.
Sourcepub async fn run_with_session_until<S, Shutdown>(
self,
session: S,
shutdown: Shutdown,
) -> Result<S, WorkerError>
pub async fn run_with_session_until<S, Shutdown>( self, session: S, shutdown: Shutdown, ) -> Result<S, WorkerError>
Test seam that handshakes, registers, and serves an injected session until shutdown fires.
§Errors
Returns WorkerError for registration, dispatch, heartbeat, or report failures.
Auto Trait Implementations§
impl !RefUnwindSafe for Worker
impl !UnwindSafe for Worker
impl Freeze for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl UnsafeUnpin 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> 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> 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