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_workflow::{
    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
    }
}

Macros§

join
Deterministic join! for use in Temporal workflows.
select
Deterministic select! for use in Temporal workflows.

Structs§

JoinAll
Future returned by join_all.

Enums§

WorkflowError
Error type for workflow operations

Traits§

ExecutableAsyncSignal
Trait for executing asynchronous signal handlers on a workflow.
ExecutableAsyncUpdate
Trait for executing asynchronous update handlers on a workflow.
ExecutableQuery
Trait for executing query handlers on a workflow.
ExecutableSyncSignal
Trait for executing synchronous signal handlers on a workflow.
ExecutableSyncUpdate
Trait for executing synchronous update handlers on a workflow.
WorkflowImplementation
Trait implemented by workflow structs to enable execution by the worker.

Functions§

join_all
Deterministic join_all for use in Temporal workflows.
serialize_result
Serialize a workflow result value to a payload.