Expand description
Functionality related to defining and interacting with workflows
This module contains traits and types for implementing workflows using the
#[workflow] and #[workflow_methods] macros.
Example usage:
use temporalio_macros::{workflow, workflow_methods};
use temporalio_sdk::{
SyncWorkflowContext, WorkflowContext, WorkflowContextView, WorkflowResult,
};
#[workflow]
pub struct MyWorkflow {
counter: u32,
}
#[workflow_methods]
impl MyWorkflow {
#[init]
pub fn new(ctx: &WorkflowContextView, input: String) -> Self {
Self { counter: 0 }
}
// Async run method uses ctx.state() for reading
#[run]
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
let counter = ctx.state(|s| s.counter);
Ok(format!("Done with counter: {}", counter))
}
// Sync signals use &mut self for direct mutations
#[signal]
pub fn increment(&mut self, ctx: &mut SyncWorkflowContext<Self>, amount: u32) {
self.counter += amount;
}
// Queries use &self with read-only context
#[query]
pub fn get_counter(&self, ctx: &WorkflowContextView) -> u32 {
self.counter
}
}Structs§
- Workflow
Definitions - Contains workflow registrations in a form ready for execution by workers.
Enums§
- Workflow
Error - Error type for workflow operations
Functions§
- deserialize_
input - Deserialize handler input from payloads.
- serialize_
output - Serialize handler output to a payload.
- serialize_
result - Serialize a workflow result value to a payload.
- wrap_
handler_ error - Wrap a handler error into WorkflowError.