Skip to content

Commit

Permalink
feat(*): add v0.8 action data filter's condition field
Browse files Browse the repository at this point in the history
Signed-off-by: LiHeng.Teh <Liheng.Teh@acronis.com>
  • Loading branch information
brlala authored and LiHeng.Teh committed Sep 29, 2022
1 parent beb77e8 commit a8a9de3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Action struct {
RetryableErrors []string `json:"retryableErrors,omitempty" validate:"omitempty,min=1"`
// Action data filter
ActionDataFilter ActionDataFilter `json:"actionDataFilter,omitempty"`
// Workflow expression evaluated against state data. Must evaluate to true or false
Condition string `json:"condition,omitempty"`
}

// FunctionRef ...
Expand Down
4 changes: 4 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func TestFromFile(t *testing.T) {
assert.IsType(t, &model.DataBasedSwitchState{}, w.States[0])
assert.IsType(t, &model.EventBasedSwitchState{}, w.States[1])
},
"./testdata/workflows/conditionbasedstate.yaml": func(t *testing.T, w *model.Workflow) {
operationState := w.States[0].(*model.OperationState)
assert.Equal(t, "${ .applicants | .age < 18 }", operationState.Actions[0].Condition)
},
"./testdata/workflows/eventbasedgreeting.sw.json": func(t *testing.T, w *model.Workflow) {
assert.Equal(t, "GreetingEvent", w.Events[0].Name)
assert.IsType(t, &model.EventState{}, w.States[0])
Expand Down
40 changes: 40 additions & 0 deletions parser/testdata/workflows/conditionbasedstate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2020 The Serverless Workflow Specification Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

id: greeting
version: '1.0'
name: Greeting Workflow
description: Greet Someone
specVersion: "0.8"
start:
stateName: Greet
functions:
- name: greetingFunction
operation: file://myapis/greetingapis.json#greeting
states:
- name: Greet
type: operation
actionMode: sequential
actions:
- functionRef:
refName: greetingFunction
parameters:
name: "${ .greet | .name }"
actionDataFilter:
toStateData: "${ .payload | .greeting }"
condition: "${ .applicants | .age < 18 }"
stateDataFilter:
dataOutputPath: "${ .greeting }"
end:
terminate: true

0 comments on commit a8a9de3

Please sign in to comment.