Skip to content

Commit

Permalink
feat(*): add InvokeKind enum (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: lsytj0413 <511121939@qq.com>

Signed-off-by: lsytj0413 <511121939@qq.com>
  • Loading branch information
lsytj0413 authored Oct 5, 2022
1 parent cc7f77a commit 10bcfba
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
12 changes: 6 additions & 6 deletions model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type FunctionRef struct {

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

type functionRefForUnmarshal FunctionRef
Expand All @@ -93,11 +93,11 @@ func (f *FunctionRef) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
f.Invoke = "sync"
f.Invoke = InvokeKindSync
return nil
case '{':
v := functionRefForUnmarshal{
Invoke: "sync",
Invoke: InvokeKindSync,
}
err = json.Unmarshal(data, &v)
if err != nil {
Expand All @@ -120,7 +120,7 @@ type WorkflowRef struct {

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

// OnParantComplete specifies how subflow execution should behave when parent workflow completes if invoke is 'async'。
// Defaults to terminate.
Expand All @@ -143,11 +143,11 @@ func (s *WorkflowRef) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
s.Invoke, s.OnParentComplete = "sync", "terminate"
s.Invoke, s.OnParentComplete = InvokeKindSync, "terminate"
return nil
case '{':
v := workflowRefForUnmarshal{
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate",
}
err = json.Unmarshal(data, &v)
Expand Down
14 changes: 7 additions & 7 deletions model/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
expect: WorkflowRef{
WorkflowID: "1",
Version: "2",
Invoke: "async",
Invoke: InvokeKindAsync,
OnParentComplete: "continue",
},
err: ``,
Expand All @@ -48,7 +48,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
expect: WorkflowRef{
WorkflowID: "1",
Version: "",
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate",
},
err: ``,
Expand All @@ -59,7 +59,7 @@ func TestWorkflowRefUnmarshalJSON(t *testing.T) {
expect: WorkflowRef{
WorkflowID: "1",
Version: "",
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate",
},
err: ``,
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestWorkflowRefValidate(t *testing.T) {
workflowRef: WorkflowRef{
WorkflowID: "1",
Version: "2",
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate",
},
err: ``,
Expand All @@ -128,7 +128,7 @@ func TestWorkflowRefValidate(t *testing.T) {
workflowRef: WorkflowRef{
WorkflowID: "1",
Version: "2",
Invoke: "async",
Invoke: InvokeKindAsync,
OnParentComplete: "continue",
},
err: ``,
Expand All @@ -138,7 +138,7 @@ func TestWorkflowRefValidate(t *testing.T) {
workflowRef: WorkflowRef{
WorkflowID: "",
Version: "2",
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate",
},
err: `Key: 'WorkflowRef.WorkflowID' Error:Field validation for 'WorkflowID' failed on the 'required' tag`,
Expand All @@ -158,7 +158,7 @@ func TestWorkflowRefValidate(t *testing.T) {
workflowRef: WorkflowRef{
WorkflowID: "1",
Version: "2",
Invoke: "sync",
Invoke: InvokeKindSync,
OnParentComplete: "terminate1",
},
err: `Key: 'WorkflowRef.OnParentComplete' Error:Field validation for 'OnParentComplete' failed on the 'oneof' tag`,
Expand Down
7 changes: 2 additions & 5 deletions model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ type EventRef struct {

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

type eventRefForUnmarshal EventRef

// UnmarshalJSON implements json.Unmarshaler
func (e *EventRef) UnmarshalJSON(data []byte) error {
v := eventRefForUnmarshal{
Invoke: "sync",
Invoke: InvokeKindSync,
}
err := json.Unmarshal(data, &v)
if err != nil {
Expand All @@ -120,6 +120,3 @@ func (e *EventRef) UnmarshalJSON(data []byte) error {
*e = EventRef(v)
return nil
}

// InvokeKind ...
type InvokeKind string
4 changes: 2 additions & 2 deletions model/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestEventRefStructLevelValidation(t *testing.T) {
TriggerEventRef: "example valid",
ResultEventRef: "example valid",
ResultEventTimeout: "PT1H",
Invoke: "sync",
Invoke: InvokeKindSync,
},
err: ``,
},
Expand All @@ -46,7 +46,7 @@ func TestEventRefStructLevelValidation(t *testing.T) {
TriggerEventRef: "example invalid",
ResultEventRef: "example invalid red",
ResultEventTimeout: "10hs",
Invoke: "sync",
Invoke: InvokeKindSync,
},
err: `Key: 'EventRef.ResultEventTimeout' Error:Field validation for 'ResultEventTimeout' failed on the 'reqiso8601duration' tag`,
},
Expand Down
11 changes: 11 additions & 0 deletions model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import (
"fmt"
)

// InvokeKind defines how the target is invoked.
type InvokeKind string

const (
// InvokeKindSync meaning that worfklow execution should wait until the target completes.
InvokeKindSync InvokeKind = "sync"

// InvokeKindAsync meaning that workflow execution should just invoke the target and should not wait until its completion.
InvokeKindAsync InvokeKind = "async"
)

const (
// DefaultExpressionLang ...
DefaultExpressionLang = "jq"
Expand Down

0 comments on commit 10bcfba

Please sign in to comment.