Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): add InvokeKind enum #97

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to break constants in different blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine since we keep the domain separated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to break constants in different blocks.

Just to put the type definition and it's value together

// 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