Skip to content

Commit db83c0d

Browse files
author
Tihomir Surdilovic
authored
Workflow error handling updates (#175) (#176)
* Workflow error handling updates Signed-off-by: Tihomir Surdilovic <[email protected]> * Updates to error and retry definitions Signed-off-by: Tihomir Surdilovic <[email protected]> * Update to error handling Signed-off-by: Tihomir Surdilovic <[email protected]> * small typo fix Signed-off-by: Tihomir Surdilovic <[email protected]> * another small typo fix Signed-off-by: Tihomir Surdilovic <[email protected]> * yet another typo fix Signed-off-by: Tihomir Surdilovic <[email protected]> * Update after review comments Signed-off-by: Tihomir Surdilovic <[email protected]> * Update to roadmap document Signed-off-by: Tihomir Surdilovic <[email protected]>
1 parent a97b2be commit db83c0d

File tree

7 files changed

+386
-363
lines changed

7 files changed

+386
-363
lines changed

examples/examples-argo.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ functions:
696696
metadata:
697697
image: python:alpine3.6
698698
command: python
699+
retries:
700+
- name: All workflow errors retry strategy
701+
maxAttempts: 10
702+
multiplier: PT2M
703+
delay: PT1M
699704
states:
700705
- name: retry-backoff
701706
type: operation
@@ -707,11 +712,11 @@ states:
707712
parameters:
708713
args:
709714
- import random; import sys; exit_code = random.choice([0, 1, 1]); sys.exit(exit_code)
710-
retry:
711-
- expression: "{{ $.[?(@.exitcode == '1')] }}"
712-
maxAttempts: 10
713-
multiplier: PT2M
714-
interval: PT1M
715+
onErrors:
716+
- error: "*"
717+
retryRef: All workflow errors retry strategy
718+
end:
719+
kind: default
715720
end:
716721
kind: default
717722
```
@@ -829,10 +834,11 @@ states:
829834
[Argo Example](https://github.com/argoproj/argo/tree/master/examples#exit-handlers)
830835
831836
*Note*: With Serverless Workflow specification we can handle Argos "onExit" functionality
832-
in couple of ways. One is the "onError" functionality to catch errors and transition to the
833-
"error" part of the workflow. Another is to send an event at the end of workflow execution
837+
in couple of ways. One is the "onErrors" functionality to define errors and transition to the parts
838+
of workflow which is capable of handling the errors.
839+
Another is to send an event at the end of workflow execution
834840
which includes the workflow status. This event can then trigger execution other workflows
835-
that can handle each status. For this example we use the "onError" definition.
841+
that can handle each status. For this example we use the "onErrors" definition.
836842
837843
<table>
838844
<tr>
@@ -919,12 +925,10 @@ states:
919925
refName: intentional-fail-function
920926
parameters:
921927
args: echo intentional failure; exit 1
922-
onError:
923-
- expression: "{{ $.errors[0] }}"
924-
errorDataFilter:
925-
dataOutputPath: "{{ $.exit-code }}"
926-
transition:
927-
nextState: send-email-state
928+
onErrors:
929+
- error: "*"
930+
transition:
931+
nextState: send-email-state
928932
- name: send-email-state
929933
type: operation
930934
actions:

examples/examples-brigade.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ states:
180180
refName: consoleLogFunction
181181
parameters:
182182
log: done
183-
onError:
184-
- expression:
185-
language: spel
186-
body: "{{ $.exceptions[0] }}"
183+
onErrors:
184+
- error: "*"
187185
transition:
188186
nextState: HandleErrorState
189187
end:

examples/examples.md

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,9 @@ states:
891891
#### Description
892892

893893
In this example we show off the states error handling capability. The workflow data input that's passed in contains
894-
missing order information that causes the function in the "ProvisionOrder" state to throw a runtime exception. With the "onError" expression we
895-
can transition the workflow to different error handling states depending on the error thrown. Each type of error
896-
in this example is handled by simple delay states, each including an error data filter which sets the exception info as their
897-
data output. If no error is caught the workflow can transition to the "ApplyOrder" state.
894+
missing order information that causes the function in the "ProvisionOrder" state to throw a runtime exception. With the "onErrors" definition we
895+
can transition the workflow to different error handling states. Each type of error
896+
in this example is handled by simple delay states. If no errors are encountered the workflow can transition to the "ApplyOrder" state.
898897

899898
Workflow data is assumed to me:
900899

@@ -956,32 +955,32 @@ The data output of the workflow contains the information of the exception caught
956955
}
957956
}
958957
],
959-
"onError": [
958+
"stateDataFilter": {
959+
"dataOutputPath": "{{ $.exceptions }}"
960+
},
961+
"transition": {
962+
"nextState":"ApplyOrder"
963+
},
964+
"onErrors": [
960965
{
961-
"expression": "{{ $.exceptions[?(@.name == 'MissingOrderIdException')] }}",
966+
"error": "Missing order id",
962967
"transition": {
963968
"nextState": "MissingId"
964969
}
965970
},
966971
{
967-
"expression": "{{ $.exceptions[?(@.name == 'MissingOrderItemException')] }}",
972+
"error": "Missing order item",
968973
"transition": {
969974
"nextState": "MissingItem"
970975
}
971976
},
972977
{
973-
"expression": "{{ $.exceptions[?(@.name == 'MissingOrderQuantityException')] }}",
978+
"error": "Missing order quantity",
974979
"transition": {
975980
"nextState": "MissingQuantity"
976981
}
977982
}
978-
],
979-
"stateDataFilter": {
980-
"dataOutputPath": "{{ $.exceptions }}"
981-
},
982-
"transition": {
983-
"nextState":"ApplyOrder"
984-
}
983+
]
985984
},
986985
{
987986
"name": "MissingId",
@@ -1041,20 +1040,20 @@ states:
10411040
refName: provisionOrderFunction
10421041
parameters:
10431042
order: "{{ $.order }}"
1044-
onError:
1045-
- expression: "{{ $.exceptions[?(@.name == 'MissingOrderIdException')] }}"
1043+
stateDataFilter:
1044+
dataOutputPath: "{{ $.exceptions }}"
1045+
transition:
1046+
nextState: ApplyOrder
1047+
onErrors:
1048+
- error: Missing order id
10461049
transition:
10471050
nextState: MissingId
1048-
- expression: "{{ $.exceptions[?(@.name == 'MissingOrderItemException')] }}"
1051+
- error: Missing order item
10491052
transition:
10501053
nextState: MissingItem
1051-
- expression: "{{ $.exceptions[?(@.name == 'MissingOrderQuantityException')] }}"
1054+
- error: Missing order quantity
10521055
transition:
10531056
nextState: MissingQuantity
1054-
stateDataFilter:
1055-
dataOutputPath: "{{ $.exceptions }}"
1056-
transition:
1057-
nextState: ApplyOrder
10581057
- name: MissingId
10591058
type: subflow
10601059
workflowId: handleMissingIdExceptionWorkflow
@@ -1156,12 +1155,9 @@ In the case job submission raises a runtime error, we transition to a SubFlow st
11561155
}
11571156
}
11581157
],
1159-
"onError": [
1158+
"onErrors": [
11601159
{
1161-
"expression": "{{ $.exceptions[0] }}",
1162-
"errorDataFilter": {
1163-
"dataOutputPath": "{{ $.exception }}"
1164-
},
1160+
"error": "*",
11651161
"transition": {
11661162
"nextState": "SubmitError"
11671163
}
@@ -1307,10 +1303,8 @@ states:
13071303
name: "{{ $.job.name }}"
13081304
actionDataFilter:
13091305
dataResultsPath: "{{ $.jobuid }}"
1310-
onError:
1311-
- expression: "{{ $.exceptions[0] }}"
1312-
errorDataFilter:
1313-
dataOutputPath: "{{ $.exception }}"
1306+
onErrors:
1307+
- error: "*"
13141308
transition:
13151309
nextState: SubmitError
13161310
stateDataFilter:

roadmap/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _Status description:_
3838
| ✔️| Update workflow start definition | [spec doc](https://github.com/cncf/wg-serverless/blob/v0.1/workflow/spec/spec.md) |
3939
| ✔️| Prepare github branch and docs for v0.1 | [branch](https://github.com/cncf/wg-serverless/tree/v0.1/workflow/spec) |
4040

41-
## v0.5 (Released November 2020)
41+
## v0.5
4242

4343
| Status | Description | Comments |
4444
| --- | --- | --- |
@@ -72,3 +72,4 @@ _Status description:_
7272
| ✔️| Events definition update - add convenience way to define multiple events that share properties | [spec doc](../specification.md) |
7373
| ✔️| Update to function and events definitions - allow inline array def as well as uri reference to external resource | [spec doc](../specification.md) |
7474
| ✔️| Enforce use of OpenAPI specification in function definitions for portability | [spec doc](../specification.md) |
75+
| ✔️| Update workflow Error Handling | [spec doc](../specification.md) |

schema/retries.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"$id": "https://serverlessworkflow.org/core/retries.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"description": "Serverless Workflow specification - retries schema",
5+
"type": "object",
6+
"retries": {
7+
"type": "array",
8+
"description": "Workflow Retry definitions. Define retry strategies that can be referenced in states onError definitions",
9+
"items": {
10+
"type": "object",
11+
"$ref": "#/definitions/retrydef"
12+
},
13+
"minItems": 1
14+
},
15+
"required": [
16+
"retries"
17+
],
18+
"definitions": {
19+
"retrydef": {
20+
"type": "object",
21+
"properties": {
22+
"name": {
23+
"type": "string",
24+
"description": "Unique retry strategy name",
25+
"minLength": 1
26+
},
27+
"delay": {
28+
"type": "string",
29+
"description": "Time delay between retry attempts (ISO 8601 duration format)"
30+
},
31+
"multiplier": {
32+
"type": "string",
33+
"description": "Multiplier value by which interval increases during each attempt (ISO 8601 time format)"
34+
},
35+
"maxAttempts": {
36+
"type": ["integer","string"],
37+
"minimum": 1,
38+
"minLength": 0,
39+
"description": "Maximum number of retry attempts."
40+
},
41+
"jitter": {
42+
"type": ["number","string"],
43+
"minimum": 0.0,
44+
"maximum": 1.0,
45+
"description": "If float type, maximum amount of random time added or subtracted from the delay between each retry relative to total delay (between 0.0 and 1.0). If string type, absolute maximum amount of random time added or subtracted from the delay between each retry (ISO 8601 duration format)"
46+
}
47+
},
48+
"required": [
49+
"name",
50+
"maxAttempts"
51+
]
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)