Skip to content

Commit 9384e9a

Browse files
authored
feat(*): add v0.8 action data filter's condition field (#83)
Signed-off-by: LiHeng.Teh <Liheng.Teh@acronis.com> Signed-off-by: LiHeng.Teh <Liheng.Teh@acronis.com>
1 parent beb77e8 commit 9384e9a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

model/action.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type Action struct {
3737
RetryableErrors []string `json:"retryableErrors,omitempty" validate:"omitempty,min=1"`
3838
// Action data filter
3939
ActionDataFilter ActionDataFilter `json:"actionDataFilter,omitempty"`
40+
// Workflow expression evaluated against state data. Must evaluate to true or false
41+
Condition string `json:"condition,omitempty"`
4042
}
4143

4244
// FunctionRef ...

parser/parser_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func TestFromFile(t *testing.T) {
8282
assert.IsType(t, &model.DataBasedSwitchState{}, w.States[0])
8383
assert.IsType(t, &model.EventBasedSwitchState{}, w.States[1])
8484
},
85+
"./testdata/workflows/conditionbasedstate.yaml": func(t *testing.T, w *model.Workflow) {
86+
operationState := w.States[0].(*model.OperationState)
87+
assert.Equal(t, "${ .applicants | .age < 18 }", operationState.Actions[0].Condition)
88+
},
8589
"./testdata/workflows/eventbasedgreeting.sw.json": func(t *testing.T, w *model.Workflow) {
8690
assert.Equal(t, "GreetingEvent", w.Events[0].Name)
8791
assert.IsType(t, &model.EventState{}, w.States[0])
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2020 The Serverless Workflow Specification Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
id: greeting
16+
version: '1.0'
17+
name: Greeting Workflow
18+
description: Greet Someone
19+
specVersion: "0.8"
20+
start:
21+
stateName: Greet
22+
functions:
23+
- name: greetingFunction
24+
operation: file://myapis/greetingapis.json#greeting
25+
states:
26+
- name: Greet
27+
type: operation
28+
actionMode: sequential
29+
actions:
30+
- functionRef:
31+
refName: greetingFunction
32+
parameters:
33+
name: "${ .greet | .name }"
34+
actionDataFilter:
35+
toStateData: "${ .payload | .greeting }"
36+
condition: "${ .applicants | .age < 18 }"
37+
stateDataFilter:
38+
dataOutputPath: "${ .greeting }"
39+
end:
40+
terminate: true

0 commit comments

Comments
 (0)