pub struct Worker { /* private fields */ }Expand description
Hosts registered Flow Step and RPC handlers over application WorkerService.
A Worker owns an internal Tokio runtime and is one-shot. Self::start first synchronizes
Attribute indexes with Dex, then blocks the calling thread while serving gRPC. Call Self::stop
from another thread to request graceful server shutdown.
§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())?;
println!("advertise {}", worker.worker_target().address());
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 an invalid bind address, 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 Worker without binding its listener.
§Errors
Returns SdkError::FlowDefinition for invalid Worker options or Service for runtime and
endpoint initialization failures. The Dex connection is lazy.
Sourcepub fn worker_target(&self) -> &WorkerTarget
pub fn worker_target(&self) -> &WorkerTarget
Returns the resolved WorkerService target that Clients should advertise to Dex.
Sourcepub fn start(&self) -> SdkResult<()>
pub fn start(&self) -> SdkResult<()>
Synchronizes Attribute indexes, serves WorkerService, and blocks until stopped or failed.
§Errors
Returns FlowDefinition if called more than once, or Service for index synchronization, timeout, bind, and server failures.
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.
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