Skip to main content

Module workflows

Module workflows 

Source
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§

WorkflowDefinitions
Contains workflow registrations in a form ready for execution by workers.

Enums§

WorkflowError
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.