|
29 | 29 | - [Switch](#switch)
|
30 | 30 | - [Try](#try)
|
31 | 31 | - [Wait](#wait)
|
| 32 | + - [While](#while) |
32 | 33 | + [Flow Directive](#flow-directive)
|
33 | 34 | + [Lifecycle Events](#lifecycle-events)
|
34 | 35 | - [Workflow Lifecycle Events](#workflow-lifecycle-events)
|
@@ -274,6 +275,7 @@ The Serverless Workflow DSL defines a list of [tasks](#task) that **must be** su
|
274 | 275 | - [Set](#set), used to dynamically set the [workflow](#workflow)'s data during the its execution.
|
275 | 276 | - [Try](#try), used to attempt executing a specified [task](#task), and to handle any resulting [errors](#error) gracefully, allowing the [workflow](#workflow) to continue without interruption.
|
276 | 277 | - [Wait](#wait), used to pause or wait for a specified duration before proceeding to the next task.
|
| 278 | +- [While](#while), used to iterate over a collection of items based on a condition, supporting both pre-test (while) and post-test (do-while) loops. |
277 | 279 |
|
278 | 280 | #### Properties
|
279 | 281 |
|
@@ -781,7 +783,7 @@ Provides the capability to execute external [containers](#container-process), [s
|
781 | 783 | | run.script | [`script`](#script-process) | `no` | The definition of the script to run.<br>*Required if `container`, `shell` and `workflow` have not been set.* |
|
782 | 784 | | run.shell | [`shell`](#shell-process) | `no` | The definition of the shell command to run.<br>*Required if `container`, `script` and `workflow` have not been set.* |
|
783 | 785 | | run.workflow | [`workflow`](#workflow-process) | `no` | The definition of the workflow to run.<br>*Required if `container`, `script` and `shell` have not been set.* |
|
784 |
| -| await | `boolean` | `no` | Determines whether or not the process to run should be awaited for.<br>*When set to `false`, the task cannot wait for the process to complete and thus cannot output the process’s result. In this case, it should simply output its transformed input.*<br>*Defaults to `true`.* | |
| 786 | +| await | `boolean` | `no` | Determines whether or not the process to run should be awaited for.<br>*When set to `false`, the task cannot wait for the process to complete and thus cannot output the process's result. In this case, it should simply output its transformed input.*<br>*Defaults to `true`.* | |
785 | 787 | | return | `string` | `no` | Configures the output of the process.<br>*Supported values are:*<br>*- `stdout`: Outputs the content of the process **STDOUT**.*<br>*- `stderr`: Outputs the content of the process **STDERR**.*<br>*- `code`: Outputs the process's **exit code**.*<br>*- `all`: Outputs the **exit code**, the **STDOUT** content and the **STDERR** content, wrapped into a new [processResult](#process-result) object.*<br>*- `none`: Does not output anything.*<br>*Defaults to `stdout`.* |
|
786 | 788 |
|
787 | 789 | ##### Examples
|
@@ -1146,6 +1148,66 @@ do:
|
1146 | 1148 | seconds: 10
|
1147 | 1149 | ```
|
1148 | 1150 |
|
| 1151 | +#### While |
| 1152 | + |
| 1153 | +Enables iterative execution of tasks based on a condition, supporting both pre-test (while) and post-test (do-while) loops. This task type is essential for scenarios requiring repetitive execution until a specific condition is met. |
| 1154 | + |
| 1155 | +##### Properties |
| 1156 | + |
| 1157 | +| Name | Type | Required | Description| |
| 1158 | +|:--|:---:|:---:|:---| |
| 1159 | +| while | `string` | `yes` | A [runtime expression](dsl.md#runtime-expressions) that represents the condition that must be met for the iteration to continue. | |
| 1160 | +| postConditionCheck | `boolean` | `no` | Determines whether the condition is evaluated after (do-while) or before (while) executing the task.<br>*If set to `true`, implements a do-while loop (post-test).*<br>*If set to `false`, implements a while loop (pre-test).*<br>*Defaults to `false`.* | |
| 1161 | +| maxIterations | `integer` | `no` | The maximum number of iterations allowed to prevent infinite loops.<br>*If not set, implementation-specific default limits apply.* | |
| 1162 | +| do | [`map[string, task]`](#task) | `yes` | The [task(s)](#task) to perform while the condition is true. | |
| 1163 | + |
| 1164 | +##### Examples |
| 1165 | + |
| 1166 | +```yaml |
| 1167 | +document: |
| 1168 | + dsl: '1.0.0' |
| 1169 | + namespace: test |
| 1170 | + name: while-example |
| 1171 | + version: '0.1.0' |
| 1172 | +do: |
| 1173 | + # While loop example (pre-test) |
| 1174 | + - fetchPaginatedData: |
| 1175 | + while: .hasNextPage == true |
| 1176 | + maxIterations: 100 |
| 1177 | + do: |
| 1178 | + - fetchPage: |
| 1179 | + call: getPageData |
| 1180 | + input: |
| 1181 | + pageToken: .nextPageToken |
| 1182 | + output: .fetchedData |
| 1183 | + - accumulateData: |
| 1184 | + run: mergeResults |
| 1185 | + input: |
| 1186 | + newData: .fetchedData |
| 1187 | + existingData: .accumulatedResults |
| 1188 | + output: .accumulatedResults |
| 1189 | +
|
| 1190 | + # Do-while loop example (post-test) |
| 1191 | + - retryOperation: |
| 1192 | + while: .retryNeeded == true |
| 1193 | + postConditionCheck: true |
| 1194 | + maxIterations: 3 |
| 1195 | + do: |
| 1196 | + - attemptOperation: |
| 1197 | + call: performOperation |
| 1198 | + output: |
| 1199 | + as: | |
| 1200 | + if .status == "failed" then |
| 1201 | + { retryNeeded: true } |
| 1202 | + else |
| 1203 | + { retryNeeded: false } |
| 1204 | + end |
| 1205 | +``` |
| 1206 | + |
| 1207 | +In the examples above: |
| 1208 | +- The first task demonstrates a while loop that fetches paginated data until there are no more pages, with a maximum of 100 iterations. |
| 1209 | +- The second task shows a do-while loop that retries an operation up to 3 times, evaluating the retry condition after each attempt. |
| 1210 | + |
1149 | 1211 | ### Flow Directive
|
1150 | 1212 |
|
1151 | 1213 | Flow Directives are commands within a workflow that dictate its progression.
|
|
0 commit comments