pub struct TaskHubGrpcWorker { /* private fields */ }Expand description
Worker that connects to a Durable Task sidecar and processes work items.
The worker opens a streaming gRPC connection to receive orchestrator and activity work items, dispatches them to registered handler functions, and returns results to the sidecar.
§Example
use dapr_durabletask::worker::TaskHubGrpcWorker;
use dapr_durabletask::task::OrchestrationContext;
let mut worker = TaskHubGrpcWorker::new("http://localhost:4001");
worker.registry_mut().add_named_orchestrator("my_orch", |ctx: OrchestrationContext| async move {
let result = ctx.call_activity("greet", "world").await?;
Ok(result)
});
worker.registry_mut().add_named_activity("greet", |_ctx, input| async move {
Ok(input)
});
let shutdown = tokio_util::sync::CancellationToken::new();
// worker.start(shutdown).await.unwrap();Implementations§
Source§impl TaskHubGrpcWorker
impl TaskHubGrpcWorker
Sourcepub fn new(host_address: &str) -> Self
pub fn new(host_address: &str) -> Self
Create a new worker that will connect to the given sidecar address.
Sourcepub fn with_options(host_address: &str, options: WorkerOptions) -> Self
pub fn with_options(host_address: &str, options: WorkerOptions) -> Self
Create a new worker with custom options.
Sourcepub fn registry_mut(&mut self) -> &mut Registry
pub fn registry_mut(&mut self) -> &mut Registry
Get a mutable reference to the registry for adding orchestrators and activities.
§Panics
Panics if called after the registry has been shared (i.e., after start()
has begun processing).
Sourcepub async fn start(&self, shutdown: CancellationToken) -> Result<()>
pub async fn start(&self, shutdown: CancellationToken) -> Result<()>
Start the worker. Runs until the cancellation token is triggered or the
reconnect policy’s max_attempts is exhausted.
§Shutdown behaviour
When the cancellation token is fired:
- The worker stops reading new work items from the sidecar stream.
- It waits for all in-flight tasks (orchestrations and activities already dispatched) to complete and send their results to the sidecar before returning.
This guarantees that no already-accepted work item is abandoned at shutdown. Work items still queued inside the sidecar but not yet dispatched to this worker are unaffected — the sidecar will re-dispatch them to the next available worker.
Auto Trait Implementations§
impl !RefUnwindSafe for TaskHubGrpcWorker
impl !UnwindSafe for TaskHubGrpcWorker
impl Freeze for TaskHubGrpcWorker
impl Send for TaskHubGrpcWorker
impl Sync for TaskHubGrpcWorker
impl Unpin for TaskHubGrpcWorker
impl UnsafeUnpin for TaskHubGrpcWorker
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