Skip to content

Commit 10efa94

Browse files
Foreach State - adding sequential exec option and batchSize for paral… (#441)
* Foreach State - adding sequential exec option and batchSize for parallel exec option Signed-off-by: Tihomir Surdilovic <[email protected]> * updated roadmap Signed-off-by: Tihomir Surdilovic <[email protected]> * Update specification.md Co-authored-by: Ricardo Zanini <[email protected]> * Update specification.md Co-authored-by: Ricardo Zanini <[email protected]> * Update specification.md Co-authored-by: Ricardo Zanini <[email protected]> Co-authored-by: Ricardo Zanini <[email protected]>
1 parent a36aa94 commit 10efa94

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

roadmap/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ _Status description:_
4343
| ✔️| Rename Delay state to Sleep state | [spec doc](../specification.md) |
4444
| ✔️| Added 'sleep' property to action definition | [spec doc](../specification.md) |
4545
| ✔️| Added Rate Limiting extension | [spec doc](../specification.md) |
46-
| ✏️ | AsyncAPI operation support | |
47-
| ✏️ | OData function definition support | |
46+
| ✔️| Update ForEach state - adding sequential exec option and batch size for parallel option | [spec doc](../specification.md) |
4847
| ✏️ | Update to retries - state specific rather than error specific | |
4948
| ✏️ | Add batching and sync option for Foreach state | |
5049
| 🚩 | Workflow invocation bindings | |
@@ -57,7 +56,6 @@ _Status description:_
5756
| 🚩 | Start discussions on Serverless Workflow Technology Compatibility Kit (TCK) | |
5857
| ✏️ | Specification primer | [google doc](https://docs.google.com/document/d/11rD3Azj63G2Si0VpokSpr-1ib3mFRFHSwN6tJb-0LQM/edit#heading=h.paewfy83tetm) continued in [wiki](https://github.com/serverlessworkflow/specification/wiki) |
5958

60-
6159
## <a name="v06"></a> v0.6
6260

6361
| Status | Description | Comments |

schema/workflow.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,14 +1447,14 @@
14471447
"type": "string",
14481448
"description": "Name of the iteration parameter that can be referenced in actions/workflow. For each parallel iteration, this param should contain an unique element of the inputCollection array"
14491449
},
1450-
"max": {
1450+
"batchSize": {
14511451
"type": [
14521452
"number",
14531453
"string"
14541454
],
14551455
"minimum": 0,
14561456
"minLength": 0,
1457-
"description": "Specifies how upper bound on how many iterations may run in parallel"
1457+
"description": "Specifies how many iterations may run in parallel at the same time. Used if 'mode' property is set to 'parallel' (default)"
14581458
},
14591459
"actions": {
14601460
"type": "array",
@@ -1505,6 +1505,15 @@
15051505
"default": false,
15061506
"description": "If true, this state is used to compensate another state. Default is false"
15071507
},
1508+
"mode": {
1509+
"type": "string",
1510+
"enum": [
1511+
"sequential",
1512+
"parallel"
1513+
],
1514+
"description": "Specifies how iterations are to be performed (sequentially or in parallel)",
1515+
"default": "parallel"
1516+
},
15081517
"metadata": {
15091518
"$ref": "common.json#/definitions/metadata"
15101519
}

specification.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,8 @@ The `timeouts` property can be used to define state specific timeout settings. I
27882788
| inputCollection | Workflow expression selecting an array element of the states data | string | yes |
27892789
| outputCollection | Workflow expression specifying an array element of the states data to add the results of each iteration | string | no |
27902790
| iterationParam | Name of the iteration parameter that can be referenced in actions/workflow. For each parallel iteration, this param should contain an unique element of the inputCollection array | string | yes |
2791-
| max | Specifies how upper bound on how many iterations may run in parallel | string or number | no |
2791+
| batchSize | Specifies how many iterations may run in parallel at the same time. Used if `mode` property is set to `parallel` (default). If not specified, its value should be the size of the `inputCollection` | string or number | no |
2792+
| mode | Specifies how iterations are to be performed (sequentially or in parallel). Default is `parallel` | string | no |
27922793
| [actions](#Action-Definition) | Actions to be executed for each of the elements of inputCollection | array | yes |
27932794
| [timeouts](#Workflow-Timeouts) | State specific timeout settings | object | no |
27942795
| [stateDataFilter](#State-data-filters) | State data filter definition | object | no |
@@ -2854,10 +2855,18 @@ actions:
28542855

28552856
ForEach states can be used to execute [actions](#Action-Definition) for each element of a data set.
28562857

2857-
Each iteration of the ForEach state should be executed in parallel.
2858+
Each iteration of the ForEach state is by default executed in parallel by default.
2859+
However, executing iterations sequentially is also possible by setting the value of the `mode` property to
2860+
`sequential`.
28582861

2859-
You can use the `max` property to set the upper bound on how many iterations may run in parallel. The default
2860-
of the `max` property is zero, which places no limit on number of parallel executions.
2862+
The `mode` property defines if iterations should be done sequentially or in parallel. By default
2863+
(if `mode` is not specified) iterations should be done in parallel.
2864+
2865+
If the default `parallel` iteration mode is used, the `batchSize` property to the number of iterations (batch)
2866+
that can be executed at a time. To give an example, if the number of iterations is 55 and `batchSize`
2867+
is set to `10`, 10 iterations are to be executed at a time, meaning that the state would execute 10 iterations in parallel,
2868+
then execute the next batch of 10 iterations. After 5 such executions, the remaining 5 iterations are to be executed in the last batch.
2869+
The batch size value must be greater than 1. If not specified, its value should be the size of the `inputCollection` (all iterations).
28612870

28622871
The `inputCollection` property is a workflow expression which selects an array in the states data. All iterations
28632872
are performed against data elements of this array. If this array does not exist, the runtime should throw

0 commit comments

Comments
 (0)