pub struct Worker { /* private fields */ }Expand description
Runs registered Flow Step and RPC handlers through outbound task streams.
A Worker owns an internal Tokio runtime and is one-shot. Self::start negotiates the Server
protocol, synchronizes Attribute indexes, then blocks while serving. Call Self::stop
from another thread to request graceful shutdown. The Worker runs at most the configured number
of handlers concurrently and needs only an outbound connection to Dex. See crate::PullWorkerOptions.
§Examples
use dex_sdk::{BlobCache, BlobCacheConfig, Registry, Worker, WorkerOptions};
use std::sync::Arc;
let cache = Arc::new(BlobCache::open(BlobCacheConfig::new(
"/tmp/dex-blobs", 64 * 1024 * 1024, 0,
)?)?);
let worker = Worker::try_new(Registry::new(), cache, WorkerOptions::new())?;
worker.start()?;Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(
registry: Registry,
blob_cache: Arc<BlobCache>,
options: WorkerOptions,
) -> Self
pub fn new( registry: Registry, blob_cache: Arc<BlobCache>, options: WorkerOptions, ) -> Self
Creates a Worker or panics when options or runtime initialization are invalid.
§Panics
Panics for invalid pull options, zero index-sync timeout, invalid Dex endpoint, or Tokio
runtime creation failure. Prefer Self::try_new for recoverable startup.
Sourcepub fn try_new(
registry: Registry,
blob_cache: Arc<BlobCache>,
options: WorkerOptions,
) -> SdkResult<Self>
pub fn try_new( registry: Registry, blob_cache: Arc<BlobCache>, options: WorkerOptions, ) -> SdkResult<Self>
Creates a one-shot pull Worker with a lazy outbound connection.
§Errors
Returns SdkError::FlowDefinition for invalid Worker options, or Service for runtime
and endpoint initialization failures. The Dex connection is lazy.
Sourcepub fn start(&self) -> SdkResult<()>
pub fn start(&self) -> SdkResult<()>
Negotiates protocol, synchronizes Attribute indexes, and serves until stopped or failed.
Stream errors are logged and retried. After Self::stop, this method drains
active handlers for the configured timeout, cancels any remaining handlers, and waits for
them to return. Call this method only once, on a dedicated thread.
§Errors
Returns FlowDefinition if called more than once, or Service for index synchronization,
timeout, and server failures.
Returns a service error exposing SdkError::pull_registration_error after draining when permanent-rejection shutdown is enabled.
Sourcepub async fn wait_pull_registered(&self) -> SdkResult<()>
pub async fn wait_pull_registered(&self) -> SdkResult<()>
Waits until every Flow type queue and the app Worker ID queue has registered once.
Safe before or after Self::start and for concurrent callers. Start the Worker on a
dedicated thread. Drop this future to cancel the wait, or use tokio::time::timeout.
Completion remains latched after shutdown; use Self::pull_registration_state for probes.
§Errors
Returns a service error exposing SdkError::pull_registration_error for a permanent rejection without another registered
stream before readiness. Returns the startup error if startup fails, or InvalidArgument
for shutdown before readiness.
tokio::time::timeout(std::time::Duration::from_secs(10), worker.wait_pull_registered()).await??;
assert!(worker.pull_registration_state().is_ready);Sourcepub fn pull_reserved_rpc_declines(&self) -> u64
pub fn pull_reserved_rpc_declines(&self) -> u64
Returns cumulative Step declines caused by reserved RPC capacity for this Worker.
The counter counts decline events. Dex may decline the same Step dispatch repeatedly while retrying it, so read the counter as a rate. Full-capacity rejections and unknown names are excluded. The count never resets and remains available after stop. Concurrent reads are safe. Export the count to a monitoring counter to identify reserve pressure.
let declines: u64 = worker.pull_reserved_rpc_declines();Sourcepub fn pull_registration_state(&self) -> PullRegistrationState
pub fn pull_registration_state(&self) -> PullRegistrationState
Returns an independent snapshot of current pull queue registrations.
Readiness latches after every queue registers once. Only a permanent rejection with no
registered stream makes it false. Successful registration clears that queue’s error.
Transient disconnects and Stop do not clear readiness. See Self::wait_pull_registered for a startup and probe example.
Sourcepub fn stop(&self)
pub fn stop(&self)
Requests shutdown of a running Worker and returns immediately.
Calling stop before or after start is safe; Self::start observes the shutdown signal.
The Worker first drains active handlers. After the drain timeout it cancels them, and
Self::start waits for their return. Half-closed pull streams wait for server EOF
until the remaining drain deadline. Stop is idempotent.
Auto Trait Implementations§
impl !Freeze for Worker
impl !RefUnwindSafe for Worker
impl !UnwindSafe 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