pub struct WorkflowContext { /* private fields */ }Implementations§
Source§impl WorkflowContext
impl WorkflowContext
Sourcepub fn workflow_identity(&self) -> Result<WorkflowIdentity>
pub fn workflow_identity(&self) -> Result<WorkflowIdentity>
Identity of the parent workflow currently being replayed.
pub fn activity<T: Serialize>( &self, activity_type: impl Into<String>, args: T, ) -> ActivityCall ⓘ
pub fn activity_on_queue<T, Q>( &self, activity_type: impl Into<String>, task_queue: Option<Q>, args: T, ) -> ActivityCall ⓘ
Sourcepub fn activity_with_options<T: Serialize>(
&self,
activity_type: impl Into<String>,
options: ActivityOptions,
args: T,
) -> ActivityCall ⓘ
pub fn activity_with_options<T: Serialize>( &self, activity_type: impl Into<String>, options: ActivityOptions, args: T, ) -> ActivityCall ⓘ
Schedule one durable activity with retry, routing, and timeout options.
Options are validated before the command is emitted. Once the command is recorded, replay consumes the same activity lifecycle at this command position and never emits a duplicate schedule.
let result = ctx
.activity_with_options(
"charge-card",
ActivityOptions::new()
.task_queue("payments")
.retry_policy(
ActivityRetryPolicy::new(4).exponential_backoff(
Duration::from_secs(1),
2,
Some(Duration::from_secs(30)),
),
)
.start_to_close_timeout(Duration::from_secs(60))
.schedule_to_close_timeout(Duration::from_secs(180))
.heartbeat_timeout(Duration::from_secs(15)),
json!([{"order_id": "order-42"}]),
)
.await;
match result {
Err(Error::ActivityFailed(failure)) => Ok(json!({
"reason": failure.reason,
"timeout_kind": failure.timeout_kind,
})),
other => other,
}pub fn wait_signal(&self, signal_name: impl Into<String>) -> SignalCall ⓘ
Sourcepub fn sleep(&self, duration: Duration) -> TimerCall ⓘ
pub fn sleep(&self, duration: Duration) -> TimerCall ⓘ
Wait for server-backed durable time without blocking the worker executor.
Polling this future emits one start_timer command and yields. The
server records the deadline, so neither worker nor server restarts reset
the wait. Replay resolves the future only from a TimerScheduled and
TimerFired pair at the same position in the shared durable-command
stream, with matching sequence, timer identity, and delay. Sub-second
durations round up because protocol deadlines use whole seconds.
let mut worker = Worker::new(client, "rust-workers");
worker.register_workflow("delayed-greeting", |ctx, _input| async move {
ctx.sleep(Duration::from_secs(5)).await?;
Ok(json!({"status": "timer fired"}))
});Sourcepub fn start_timer(&self, duration: Duration) -> TimerCall ⓘ
pub fn start_timer(&self, duration: Duration) -> TimerCall ⓘ
Alias for WorkflowContext::sleep for timer-oriented workflow code.
Sourcepub fn start_child_workflow<T: Serialize>(
&self,
workflow_type: impl Into<String>,
options: ChildWorkflowOptions,
args: T,
) -> ChildWorkflowCall ⓘ
pub fn start_child_workflow<T: Serialize>( &self, workflow_type: impl Into<String>, options: ChildWorkflowOptions, args: T, ) -> ChildWorkflowCall ⓘ
Start a named durable child on an explicit queue and await its result.
The command is recorded in the parent’s sequence-ordered durable command
stream. Replay keeps a scheduled child pending without emitting another
start, or consumes its matching terminal ChildRun* outcome. Successful
values preserve the history payload codec and include both sides of the
durable relationship; failures are returned as
Error::ChildWorkflowFailed.
let mut worker = Worker::new(client, "parent-workers");
worker.register_workflow("order-parent", |ctx, _input| async move {
let child = ctx
.start_child_workflow(
"fulfil-order",
ChildWorkflowOptions::new("fulfilment-workers")
.parent_close_policy(ParentClosePolicy::RequestCancel),
json!([{"order_id": "order-42"}]),
)
.await?;
Ok(child.result)
});Trait Implementations§
Source§impl Clone for WorkflowContext
impl Clone for WorkflowContext
Source§fn clone(&self) -> WorkflowContext
fn clone(&self) -> WorkflowContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more