Overview
Signals are methods on your workflow class marked with the#[SignalMethod] attribute. They allow external code to communicate with a running workflow without waiting for a response.
Defining Signal Methods
Mark methods with the#[SignalMethod] attribute to make them callable from outside the workflow:
Signal methods must return
void. They cannot return values to the caller.Sending Signals
Send signals to a workflow using the workflow instance:Signal Characteristics
Asynchronous
Signals return immediately without waiting for the workflow to process them
Persistent
Signals are queued and persisted, ensuring delivery even if the workflow is paused
Ordered
Signals are processed in the order they are received
Void Return
Signal methods cannot return values to the caller
Using Signals with Await
A common pattern is to use signals to modify workflow state that is being awaited:Multiple Signals
Workflows can have multiple signal methods for different purposes:Webhook Integration
Signals can be exposed as webhooks for external systems to trigger:When using the
#[Webhook] attribute, the signal can be triggered via HTTP POST to the workflow’s webhook URL.Signal Replay Safety
Signals are deterministic and replay-safe. The workflow execution history ensures that signals are processed consistently during replays:Use Cases
Human Intervention
Allow humans to approve, reject, or modify workflow execution
External Events
React to external system events via webhooks
Cancellation
Provide a mechanism to cancel long-running workflows
Dynamic Updates
Update workflow parameters while execution is in progress
Best Practices
Keep signal methods simple
Keep signal methods simple
Signal methods should only update workflow state. Avoid complex logic or blocking operations.
Use meaningful names
Use meaningful names
Signal method names should clearly describe their purpose (e.g.,
cancel(), approve(), updateAddress()).Validate signal parameters
Validate signal parameters
Always validate parameters passed to signal methods to prevent invalid state.
Document signal behavior
Document signal behavior
Clearly document what each signal does and when it should be used.
Related Patterns
- Await Conditions - Wait for signal-modified state
- Queries and Updates - Read and modify workflow state
- Timers - Combine signals with timeouts