Skip to content

Commit 10bcfba

Browse files
authored
feat(*): add InvokeKind enum (#97)
Signed-off-by: lsytj0413 <511121939@qq.com> Signed-off-by: lsytj0413 <511121939@qq.com>
1 parent cc7f77a commit 10bcfba

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

model/action.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type FunctionRef struct {
7474

7575
// Invoke specifies if the subflow should be invoked sync or async.
7676
// Defaults to sync.
77-
Invoke string `json:"invoke,omitempty" validate:"required,oneof=async sync"`
77+
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`
7878
}
7979

8080
type functionRefForUnmarshal FunctionRef
@@ -93,11 +93,11 @@ func (f *FunctionRef) UnmarshalJSON(data []byte) error {
9393
if err != nil {
9494
return err
9595
}
96-
f.Invoke = "sync"
96+
f.Invoke = InvokeKindSync
9797
return nil
9898
case '{':
9999
v := functionRefForUnmarshal{
100-
Invoke: "sync",
100+
Invoke: InvokeKindSync,
101101
}
102102
err = json.Unmarshal(data, &v)
103103
if err != nil {
@@ -120,7 +120,7 @@ type WorkflowRef struct {
120120

121121
// Invoke specifies if the subflow should be invoked sync or async.
122122
// Defaults to sync.
123-
Invoke string `json:"invoke,omitempty" validate:"required,oneof=async sync"`
123+
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`
124124

125125
// OnParantComplete specifies how subflow execution should behave when parent workflow completes if invoke is 'async'。
126126
// Defaults to terminate.
@@ -143,11 +143,11 @@ func (s *WorkflowRef) UnmarshalJSON(data []byte) error {
143143
if err != nil {
144144
return err
145145
}
146-
s.Invoke, s.OnParentComplete = "sync", "terminate"
146+
s.Invoke, s.OnParentComplete = InvokeKindSync, "terminate"
147147
return nil
148148
case '{':
149149
v := workflowRefForUnmarshal{
150-
Invoke: "sync",
150+
Invoke: InvokeKindSync,
151151
OnParentComplete: "terminate",
152152
}
153153
err = json.Unmarshal(data, &v)

model/action_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
3737
expect: WorkflowRef{
3838
WorkflowID: "1",
3939
Version: "2",
40-
Invoke: "async",
40+
Invoke: InvokeKindAsync,
4141
OnParentComplete: "continue",
4242
},
4343
err: ``,
@@ -48,7 +48,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
4848
expect: WorkflowRef{
4949
WorkflowID: "1",
5050
Version: "",
51-
Invoke: "sync",
51+
Invoke: InvokeKindSync,
5252
OnParentComplete: "terminate",
5353
},
5454
err: ``,
@@ -59,7 +59,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
5959
expect: WorkflowRef{
6060
WorkflowID: "1",
6161
Version: "",
62-
Invoke: "sync",
62+
Invoke: InvokeKindSync,
6363
OnParentComplete: "terminate",
6464
},
6565
err: ``,
@@ -118,7 +118,7 @@ func TestWorkflowRefValidate(t *testing.T) {
118118
workflowRef: WorkflowRef{
119119
WorkflowID: "1",
120120
Version: "2",
121-
Invoke: "sync",
121+
Invoke: InvokeKindSync,
122122
OnParentComplete: "terminate",
123123
},
124124
err: ``,
@@ -128,7 +128,7 @@ func TestWorkflowRefValidate(t *testing.T) {
128128
workflowRef: WorkflowRef{
129129
WorkflowID: "1",
130130
Version: "2",
131-
Invoke: "async",
131+
Invoke: InvokeKindAsync,
132132
OnParentComplete: "continue",
133133
},
134134
err: ``,
@@ -138,7 +138,7 @@ func TestWorkflowRefValidate(t *testing.T) {
138138
workflowRef: WorkflowRef{
139139
WorkflowID: "",
140140
Version: "2",
141-
Invoke: "sync",
141+
Invoke: InvokeKindSync,
142142
OnParentComplete: "terminate",
143143
},
144144
err: `Key: 'WorkflowRef.WorkflowID' Error:Field validation for 'WorkflowID' failed on the 'required' tag`,
@@ -158,7 +158,7 @@ func TestWorkflowRefValidate(t *testing.T) {
158158
workflowRef: WorkflowRef{
159159
WorkflowID: "1",
160160
Version: "2",
161-
Invoke: "sync",
161+
Invoke: InvokeKindSync,
162162
OnParentComplete: "terminate1",
163163
},
164164
err: `Key: 'WorkflowRef.OnParentComplete' Error:Field validation for 'OnParentComplete' failed on the 'oneof' tag`,

model/event.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ type EventRef struct {
102102

103103
// Invoke specifies if the subflow should be invoked sync or async.
104104
// Defaults to sync.
105-
Invoke string `json:"invoke,omitempty" validate:"required,oneof=async sync"`
105+
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`
106106
}
107107

108108
type eventRefForUnmarshal EventRef
109109

110110
// UnmarshalJSON implements json.Unmarshaler
111111
func (e *EventRef) UnmarshalJSON(data []byte) error {
112112
v := eventRefForUnmarshal{
113-
Invoke: "sync",
113+
Invoke: InvokeKindSync,
114114
}
115115
err := json.Unmarshal(data, &v)
116116
if err != nil {
@@ -120,6 +120,3 @@ func (e *EventRef) UnmarshalJSON(data []byte) error {
120120
*e = EventRef(v)
121121
return nil
122122
}
123-
124-
// InvokeKind ...
125-
type InvokeKind string

model/event_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestEventRefStructLevelValidation(t *testing.T) {
3636
TriggerEventRef: "example valid",
3737
ResultEventRef: "example valid",
3838
ResultEventTimeout: "PT1H",
39-
Invoke: "sync",
39+
Invoke: InvokeKindSync,
4040
},
4141
err: ``,
4242
},
@@ -46,7 +46,7 @@ func TestEventRefStructLevelValidation(t *testing.T) {
4646
TriggerEventRef: "example invalid",
4747
ResultEventRef: "example invalid red",
4848
ResultEventTimeout: "10hs",
49-
Invoke: "sync",
49+
Invoke: InvokeKindSync,
5050
},
5151
err: `Key: 'EventRef.ResultEventTimeout' Error:Field validation for 'ResultEventTimeout' failed on the 'reqiso8601duration' tag`,
5252
},

model/workflow.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ import (
1919
"fmt"
2020
)
2121

22+
// InvokeKind defines how the target is invoked.
23+
type InvokeKind string
24+
25+
const (
26+
// InvokeKindSync meaning that worfklow execution should wait until the target completes.
27+
InvokeKindSync InvokeKind = "sync"
28+
29+
// InvokeKindAsync meaning that workflow execution should just invoke the target and should not wait until its completion.
30+
InvokeKindAsync InvokeKind = "async"
31+
)
32+
2233
const (
2334
// DefaultExpressionLang ...
2435
DefaultExpressionLang = "jq"

0 commit comments

Comments
 (0)