Documentation Index
Fetch the complete documentation index at: https://mintlify.com/serverlessworkflow/specification/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Tasks are the fundamental computing units of a workflow. They define the different types of actions that a workflow can perform, including the ability to mutate their input and output data. Tasks can also write to and modify the context data, enabling complex and dynamic workflow behaviors.All tasks share common properties for input/output transformation, error handling, timeouts, and flow control, making them consistent and predictable across different task types.
Task Types
The Serverless Workflow DSL defines several default task types that runtimes must implement:Call Task
Used to call services and/or functions:The function or service to call (e.g.,
http, grpc, openapi, asyncapi, a2a, or a custom function)Parameters to pass to the function or service
Do Task
Used to define one or more subtasks to perform in sequence:A list of tasks to execute sequentially
Emit Task
Used to emit Cloud Events:The Cloud Event to emit, conforming to the CloudEvents specification
For Task
Used to iterate over a collection of items, conditionally performing a task for each:The name of the variable to store each item
Runtime expression that evaluates to the collection to iterate over
Optional name of the variable to store the current iteration index
Tasks to execute for each item
Fork Task
Used to define two or more subtasks to perform in parallel:List of task branches to execute in parallel
If true, the first branch to complete successfully wins and other branches are cancelled
Listen Task
Used to listen for one or more events:Defines the events to listen for using
any or all semanticsRaise Task
Used to raise an error and potentially fault the workflow:The error to raise, following RFC 7807 Problem Details format
Run Task
Used to run a container, script, shell command, or another workflow:Container Process
Script Process
Shell Process
Workflow Process
Configuration for running a container
Configuration for executing a script
Configuration for running a shell command
Configuration for running another workflow
Set Task
Used to dynamically set the workflow’s data during execution:Key-value pairs to set in the workflow context
Switch Task
Used to dynamically select and execute one of multiple alternative paths:Array of conditional branches with
when conditions and then targetsTry Task
Used to attempt executing a task and handle errors gracefully:The task to attempt
Error handling configuration
Wait Task
Used to pause or wait for a specified duration:Either a duration object (seconds, minutes, hours, days) or an ISO 8601 timestamp
Common Task Properties
All tasks share a set of common properties that provide consistent behavior:Input Transformation
JSON Schema to validate task input before execution
Runtime expression to transform raw task input. Defaults to
${ . }The
input.from expression evaluates the raw task input and produces the transformed input that will be set as the $input runtime argument.Output Transformation
Runtime expression to transform raw task output. Defaults to
${ . }JSON Schema to validate task output after transformation
Context Export
Runtime expression to update the workflow context. Defaults to returning existing context
JSON Schema to validate the exported context
The
export.as expression evaluates the transformed task output and produces the new workflow context, which replaces the current $context.Conditional Execution
Runtime expression that determines whether the task should execute. If false, the task is skipped.
Timeout Configuration
Duration object specifying when the task should timeout
Flow Directives
Specifies the next task to execute or
end to gracefully end the workflowTask Lifecycle
Tasks go through several phases during their execution:Status Phases
| Phase | Description |
|---|---|
pending | The task has been created and is pending execution |
running | The task is currently executing |
waiting | The task is waiting for an event or time interval |
suspended | The task has been manually paused |
cancelled | The task was cancelled before completion |
faulted | The task encountered an error |
completed | The task completed successfully |
Execution Flow
Task Execution Steps
Task Naming and References
Tasks are defined as key-value pairs where the key is the task name:Task names must be unique within their scope and should be descriptive of the task’s purpose.
Best Practices
Use Descriptive Names
Validate Inputs and Outputs
Handle Errors Gracefully
Set Appropriate Timeouts
Transform Data Efficiently
Common Patterns
Sequential Processing with Data Transformation
Parallel API Calls with Aggregation
Conditional Task Execution
Error Handling with Fallback
Related Topics
- Workflows - Learn about workflow structure and components
- Task Flow - Understand how tasks are executed and controlled
- Data Flow - Learn how data flows through tasks
- Runtime Expressions - Use expressions in task definitions
- Fault Tolerance - Handle errors and implement retry logic
- Timeouts - Configure task and workflow timeouts