pub enum WorkItem {
StartOrchestration {
instance: String,
orchestration: String,
input: String,
version: Option<String>,
parent_instance: Option<String>,
parent_id: Option<u64>,
execution_id: u64,
},
ActivityExecute {
instance: String,
execution_id: u64,
id: u64,
name: String,
input: String,
session_id: Option<String>,
tag: Option<String>,
},
ActivityCompleted {
instance: String,
execution_id: u64,
id: u64,
result: String,
},
ActivityFailed {
instance: String,
execution_id: u64,
id: u64,
details: ErrorDetails,
},
TimerFired {
instance: String,
execution_id: u64,
id: u64,
fire_at_ms: u64,
},
ExternalRaised {
instance: String,
name: String,
data: String,
},
SubOrchCompleted {
parent_instance: String,
parent_execution_id: u64,
parent_id: u64,
result: String,
},
SubOrchFailed {
parent_instance: String,
parent_execution_id: u64,
parent_id: u64,
details: ErrorDetails,
},
CancelInstance {
instance: String,
reason: String,
},
ContinueAsNew {
instance: String,
orchestration: String,
input: String,
version: Option<String>,
carry_forward_events: Vec<(String, String)>,
initial_custom_status: Option<String>,
},
QueueMessage {
instance: String,
name: String,
data: String,
},
}Expand description
Provider-backed work queue items the runtime consumes continually.
WorkItems represent messages that flow through provider-managed queues. They are serialized/deserialized using serde_json for storage.
§Queue Routing
Different WorkItem types go to different queues:
StartOrchestration, ContinueAsNew, ActivityCompleted/Failed, TimerFired, ExternalRaised, SubOrchCompleted/Failed, CancelInstance→ Orchestrator queue- TimerFired items use
visible_at = fire_at_msfor delayed visibility
- TimerFired items use
ActivityExecute→ Worker queue
§Instance ID Extraction
Most WorkItems have an instance field. Sub-orchestration completions use parent_instance.
Providers need to extract the instance ID for routing. SQLite example:
let instance = match &item {
WorkItem::StartOrchestration { instance, .. } |
WorkItem::ActivityCompleted { instance, .. } |
WorkItem::CancelInstance { instance, .. } => instance,
WorkItem::SubOrchCompleted { parent_instance, .. } => parent_instance,
_ => return Err("unexpected item type"),
};§Execution ID Tracking
WorkItems for activities, timers, and sub-orchestrations include execution_id.
This allows providers to route completions to the correct execution when ContinueAsNew creates multiple executions.
Critical: Completions with mismatched execution_id should still be enqueued (the runtime filters them).
Variants§
StartOrchestration
Start a new orchestration instance
- Instance metadata is created by runtime via ack_orchestration_item metadata (not on enqueue)
execution_id: The execution ID for this start (usually INITIAL_EXECUTION_ID=1)version: None means runtime will resolve from registry
Fields
ActivityExecute
Execute an activity (goes to worker queue)
id: event_id from ActivityScheduled (for correlation)- Worker will enqueue ActivityCompleted or ActivityFailed
Fields
ActivityCompleted
Activity completed successfully (goes to orchestrator queue)
id: source_event_id referencing the ActivityScheduled event- Triggers next orchestration turn
ActivityFailed
Activity failed with error (goes to orchestrator queue)
id: source_event_id referencing the ActivityScheduled event- Triggers next orchestration turn
TimerFired
Timer fired (goes to orchestrator queue with delayed visibility)
- Created directly by runtime when timer is scheduled
- Enqueued to orchestrator queue with
visible_at = fire_at_ms - Orchestrator dispatcher processes when
visible_at <= now()
ExternalRaised
External event raised (goes to orchestrator queue)
- Matched by
nameto ExternalSubscribed events data: JSON payload from external system
SubOrchCompleted
Sub-orchestration completed (goes to parent’s orchestrator queue)
- Routes to
parent_instance, not the child parent_id: event_id from parent’s SubOrchestrationScheduled event
SubOrchFailed
Sub-orchestration failed (goes to parent’s orchestration queue)
- Routes to
parent_instance, not the child parent_id: event_id from parent’s SubOrchestrationScheduled event
CancelInstance
Request orchestration cancellation (goes to orchestrator queue)
- Runtime will append OrchestrationCancelRequested event
- Eventually results in OrchestrationFailed with “canceled: {reason}”
ContinueAsNew
Continue orchestration as new execution (goes to orchestrator queue)
- Signals the end of current execution and start of next
- Runtime will create Event::OrchestrationStarted for next execution
- Provider should create new execution (see ExecutionMetadata.create_next_execution)
Fields
QueueMessage
Persistent external event raised (goes to orchestrator queue).
Matched by name using FIFO mailbox semantics — events stick around until consumed.