Workflow Activity
What is a Workflow Activity?
A Workflow Activity is an Activity Execution started as a step in a Workflow, using the Temporal SDK from your Workflow code.
The Workflow schedules the Activity, the Temporal Service dispatches an Activity Task to an Activity Worker polling the Activity's Task Queue, and the result is delivered back to the Workflow when the Activity Execution closes. Each step is recorded in the Workflow Execution's Event History.
Use a Workflow Activity when you need to orchestrate multiple steps: sequencing, branching on a result, compensating a failure, waiting on a Signal or Timer between steps. If you just need to execute a single Activity, use a Standalone Activity instead.
Activity options
You set Activity Options in your Workflow code when you schedule the Activity. At minimum, specify a timeout - typically the Start-To-Close Timeout.
- Timeouts: Schedule-To-Start, Start-To-Close, Schedule-To-Close, and Heartbeat.
- Retry Policy: Activities retry automatically by default, with exponential backoff and unlimited Maximum Attempts.
- Task Queue: routes the Activity Task to the Workers that should run it. It doesn't have to be the Workflow's Task Queue.
Event History
A Workflow Activity writes Activity Events to the Workflow Execution's Event History, such as ActivityTaskScheduled, ActivityTaskStarted, and ActivityTaskCompleted.
Two consequences follow:
- Replay uses the recorded result. A completed Activity isn't executed again when the Workflow replays.
- Arguments and return values are persisted. They count toward Event History limits, so be mindful of payload size and of how many Activities a single Workflow Execution schedules.
Activity Id
A Workflow Activity's Activity Id is unique among the open Activity Executions of a Workflow Run. A Workflow Run may reuse an Activity Id once an earlier Activity Execution with that Id has closed.
Cancellation
A Workflow Activity can't be canceled directly. It receives a Cancellation request as a result of its Workflow being canceled, or because the Workflow code requested it. Activities must Heartbeat to receive Cancellation.
The Workflow decides whether to wait for the Cancellation to be accepted or to proceed without waiting.
Asynchronous completion
A Workflow Activity can return from its function without completing the Activity Execution, leaving an external system to Heartbeat progress and deliver the final result. See Asynchronous Activity Completion.
Operator commands
Pause, Unpause, Reset and Update Options let an operator intervene in a running Workflow Activity. These commands are in Public Preview.
See Activity Operations for details.