Skip to content

Commit

Permalink
Upgrade to 1.2.0 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Jan 24, 2023
1 parent 37af5d4 commit 877c7ea
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 386 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/gin-gonic/gin v1.8.2
github.com/indeedeng/iwf-golang-sdk v1.1.0
github.com/indeedeng/iwf-golang-sdk v1.2.0
github.com/urfave/cli v1.22.10
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/indeedeng/iwf-golang-sdk v1.1.0 h1:5fFm/QYBQ2XQdl5yu6wzaypKJSVD2DT4fGzgZ2xVkI0=
github.com/indeedeng/iwf-golang-sdk v1.1.0/go.mod h1:8TkeSg7Usu1nRfeZPBiRupYdTbZ+5XipJpq2RvHhm0w=
github.com/indeedeng/iwf-golang-sdk v1.2.0 h1:FjlY+r36f18mPJEwWWn5x29R7H7hKv85yFYFxH9Ef1I=
github.com/indeedeng/iwf-golang-sdk v1.2.0/go.mod h1:8TkeSg7Usu1nRfeZPBiRupYdTbZ+5XipJpq2RvHhm0w=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
22 changes: 7 additions & 15 deletions workflows/basic/basic_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ package basic

import "github.com/indeedeng/iwf-golang-sdk/iwf"

type BasicWorkflow struct{}
type BasicWorkflow struct {
iwf.EmptyCommunicationSchema
iwf.EmptyPersistenceSchema
iwf.DefaultWorkflowType
}

func (b BasicWorkflow) GetStates() []iwf.StateDef {
return []iwf.StateDef{
iwf.NewStartingState(&basicWorkflowState1{}),
iwf.NewNonStartingState(&basicWorkflowState2{}),
iwf.StartingStateDef(&basicWorkflowState1{}),
iwf.NonStartingStateDef(&basicWorkflowState2{}),
}
}

func (b BasicWorkflow) GetPersistenceSchema() []iwf.PersistenceFieldDef {
return nil
}

func (b BasicWorkflow) GetCommunicationSchema() []iwf.CommunicationMethodDef {
return nil
}

func (b BasicWorkflow) GetWorkflowType() string {
return ""
}
20 changes: 4 additions & 16 deletions workflows/basic/basic_workflow_state1.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package basic

import (
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl"
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type basicWorkflowState1 struct{}

const BasicWorkflowState1Id = "basicWorkflowState1"

func (b basicWorkflowState1) GetStateId() string {
return BasicWorkflowState1Id
type basicWorkflowState1 struct {
iwf.DefaultStateIdAndOptions
}

func (b basicWorkflowState1) Start(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
Expand All @@ -19,13 +14,6 @@ func (b basicWorkflowState1) Start(ctx iwf.WorkflowContext, input iwf.Object, pe

func (b basicWorkflowState1) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {
var i int
err := input.Get(&i)
if err != nil {
return nil, err
}
return iwf.SingleNextState(basicWorkflowState2Id, i+1), nil
}

func (b basicWorkflowState1) GetStateOptions() *iwfidl.WorkflowStateOptions {
return nil
input.Get(&i)
return iwf.SingleNextState(basicWorkflowState2{}, i+1), nil
}
18 changes: 3 additions & 15 deletions workflows/basic/basic_workflow_state2.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package basic

import (
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl"
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type basicWorkflowState2 struct{}

const basicWorkflowState2Id = "basicWorkflowState2"

func (b basicWorkflowState2) GetStateId() string {
return basicWorkflowState2Id
type basicWorkflowState2 struct {
iwf.DefaultStateIdAndOptions
}

func (b basicWorkflowState2) Start(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
Expand All @@ -19,13 +14,6 @@ func (b basicWorkflowState2) Start(ctx iwf.WorkflowContext, input iwf.Object, pe

func (b basicWorkflowState2) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {
var i int
err := input.Get(&i)
if err != nil {
return nil, err
}
input.Get(&i)
return iwf.GracefulCompleteWorkflow(i + 1), nil
}

func (b basicWorkflowState2) GetStateOptions() *iwfidl.WorkflowStateOptions {
return nil
}
23 changes: 9 additions & 14 deletions workflows/interstate/interstate_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@ package interstate

import "github.com/indeedeng/iwf-golang-sdk/iwf"

type InterStateWorkflow struct{}
type InterStateWorkflow struct {
iwf.EmptyPersistenceSchema
iwf.DefaultWorkflowType
}

const interStateChannel1 = "test-inter-state-channel-1"
const interStateChannel2 = "test-inter-state-channel-2"

func (b InterStateWorkflow) GetStates() []iwf.StateDef {
return []iwf.StateDef{
iwf.NewStartingState(&interStateWorkflowState0{}),
iwf.NewNonStartingState(&interStateWorkflowState1{}),
iwf.NewNonStartingState(&interStateWorkflowState2{}),
iwf.StartingStateDef(&interStateWorkflowState0{}),
iwf.NonStartingStateDef(&interStateWorkflowState1{}),
iwf.NonStartingStateDef(&interStateWorkflowState2{}),
}
}

func (b InterStateWorkflow) GetPersistenceSchema() []iwf.PersistenceFieldDef {
return nil
}

func (b InterStateWorkflow) GetCommunicationSchema() []iwf.CommunicationMethodDef {
return []iwf.CommunicationMethodDef{
iwf.NewInterstateChannelDef(interStateChannel1),
iwf.NewInterstateChannelDef(interStateChannel2),
iwf.InterstateChannelDef(interStateChannel1),
iwf.InterstateChannelDef(interStateChannel2),
}
}

func (b InterStateWorkflow) GetWorkflowType() string {
return ""
}
6 changes: 4 additions & 2 deletions workflows/interstate/interstate_workflow_state0.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type interStateWorkflowState0 struct{}
type interStateWorkflowState0 struct {
iwf.DefaultStateIdAndOptions
}

const InterStateWorkflowState0Id = "interStateWorkflowState0"

Expand All @@ -18,7 +20,7 @@ func (b interStateWorkflowState0) Start(ctx iwf.WorkflowContext, input iwf.Objec
}

func (b interStateWorkflowState0) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {
return iwf.MultiNextStatesByStateIds(interStateWorkflowState1Id, interStateWorkflowState2Id), nil
return iwf.MultiNextStates(interStateWorkflowState1{}, interStateWorkflowState2{}), nil
}

func (b interStateWorkflowState0) GetStateOptions() *iwfidl.WorkflowStateOptions {
Expand Down
19 changes: 4 additions & 15 deletions workflows/interstate/interstate_workflow_state1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import (
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type interStateWorkflowState1 struct{}

const interStateWorkflowState1Id = "interStateWorkflowState1"

func (b interStateWorkflowState1) GetStateId() string {
return interStateWorkflowState1Id
type interStateWorkflowState1 struct {
iwf.DefaultStateIdAndOptions
}

func (b interStateWorkflowState1) Start(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
Expand All @@ -25,16 +21,9 @@ func (b interStateWorkflowState1) Decide(ctx iwf.WorkflowContext, input iwf.Obje
var i int
cmd1 := commandResults.GetInterStateChannelCommandResultById("id1")
cmd2 := commandResults.GetInterStateChannelCommandResultById("id2")
err := cmd2.Value.Get(&i)
if err != nil {
return nil, err
}
cmd2.Value.Get(&i)
if cmd1.Status == iwfidl.WAITING && i == 2 {
return iwf.GracefulCompletingWorkflow, nil
}
return nil, fmt.Errorf("error in executing " + interStateWorkflowState1Id)
}

func (b interStateWorkflowState1) GetStateOptions() *iwfidl.WorkflowStateOptions {
return nil
return nil, fmt.Errorf("error in executing " + ctx.GetStateExecutionId())
}
18 changes: 3 additions & 15 deletions workflows/interstate/interstate_workflow_state2.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package interstate

import (
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl"
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type interStateWorkflowState2 struct{}

const interStateWorkflowState2Id = "interStateWorkflowState2"

func (b interStateWorkflowState2) GetStateId() string {
return interStateWorkflowState2Id
type interStateWorkflowState2 struct {
iwf.DefaultStateIdAndOptions
}

func (b interStateWorkflowState2) Start(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
err := communication.PublishInterstateChannel(interStateChannel2, 2)
if err != nil {
return nil, err
}
communication.PublishInterstateChannel(interStateChannel2, 2)
return iwf.EmptyCommandRequest(), nil
}

func (b interStateWorkflowState2) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {
return iwf.DeadEnd, nil
}

func (b interStateWorkflowState2) GetStateOptions() *iwfidl.WorkflowStateOptions {
return nil
}
31 changes: 13 additions & 18 deletions workflows/persistence/persistence_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type PersistenceWorkflow struct{}
type PersistenceWorkflow struct {
iwf.EmptyCommunicationSchema
iwf.DefaultWorkflowType
}

const (
testDataObjectKey = "test-data-object"
Expand All @@ -20,27 +23,19 @@ const (

func (b PersistenceWorkflow) GetStates() []iwf.StateDef {
return []iwf.StateDef{
iwf.NewStartingState(&persistenceWorkflowState1{}),
iwf.NewNonStartingState(&persistenceWorkflowState2{}),
iwf.StartingStateDef(&persistenceWorkflowState1{}),
iwf.NonStartingStateDef(&persistenceWorkflowState2{}),
}
}

func (b PersistenceWorkflow) GetPersistenceSchema() []iwf.PersistenceFieldDef {
return []iwf.PersistenceFieldDef{
iwf.NewDataObjectDef(testDataObjectKey),
iwf.NewSearchAttributeDef(testSearchAttributeInt, iwfidl.INT),
iwf.NewSearchAttributeDef(testSearchAttributeDatetime, iwfidl.DATETIME),
iwf.NewSearchAttributeDef(testSearchAttributeBool, iwfidl.BOOL),
iwf.NewSearchAttributeDef(testSearchAttributeDouble, iwfidl.DOUBLE),
iwf.NewSearchAttributeDef(testSearchAttributeText, iwfidl.TEXT),
iwf.NewSearchAttributeDef(testSearchAttributeKeyword, iwfidl.KEYWORD),
iwf.DataObjectDef(testDataObjectKey),
iwf.SearchAttributeDef(testSearchAttributeInt, iwfidl.INT),
iwf.SearchAttributeDef(testSearchAttributeDatetime, iwfidl.DATETIME),
iwf.SearchAttributeDef(testSearchAttributeBool, iwfidl.BOOL),
iwf.SearchAttributeDef(testSearchAttributeDouble, iwfidl.DOUBLE),
iwf.SearchAttributeDef(testSearchAttributeText, iwfidl.TEXT),
iwf.SearchAttributeDef(testSearchAttributeKeyword, iwfidl.KEYWORD),
}
}

func (b PersistenceWorkflow) GetCommunicationSchema() []iwf.CommunicationMethodDef {
return nil
}

func (b PersistenceWorkflow) GetWorkflowType() string {
return ""
}
55 changes: 11 additions & 44 deletions workflows/persistence/persistence_workflow_state1.go
Original file line number Diff line number Diff line change
@@ -1,72 +1,39 @@
package persistence

import (
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl"
"github.com/indeedeng/iwf-golang-sdk/iwf"
)

type persistenceWorkflowState1 struct{}

const PersistenceWorkflowState1Id = "persistenceWorkflowState1"

func (b persistenceWorkflowState1) GetStateId() string {
return PersistenceWorkflowState1Id
type persistenceWorkflowState1 struct {
iwf.DefaultStateIdAndOptions
}

func (b persistenceWorkflowState1) Start(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
var do ExampleDataObjectModel
err := persistence.GetDataObject(testDataObjectKey, &do)
if err != nil {
return nil, err
}
persistence.GetDataObject(testDataObjectKey, &do)
if do.StrValue == "" && do.IntValue == 0 {
err := input.Get(&do)
if err != nil {
return nil, err
}
input.Get(&do)
if do.StrValue == "" || do.IntValue == 0 {
panic("this value shouldn't be empty as we got it from start request")
}
} else {
panic("this value should be empty because we haven't set it before")
}
err = persistence.SetDataObject(testDataObjectKey, do)
if err != nil {
return nil, err
}
err = persistence.SetSearchAttributeInt(testSearchAttributeInt, 1)
if err != nil {
return nil, err
}
persistence.SetDataObject(testDataObjectKey, do)
persistence.SetSearchAttributeInt(testSearchAttributeInt, 1)

return iwf.EmptyCommandRequest(), nil
}

func (b persistenceWorkflowState1) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {
iv, err := persistence.GetSearchAttributeInt(testSearchAttributeInt)
if err != nil {
return nil, err
}
iv := persistence.GetSearchAttributeInt(testSearchAttributeInt)
if iv != 1 {
panic("this value must be 1 because it got set by Start API")
}

var do ExampleDataObjectModel
err = persistence.GetDataObject(testDataObjectKey, &do)
if err != nil {
return nil, err
}
err = persistence.SetSearchAttributeDatetime(testSearchAttributeDatetime, do.Datetime)
if err != nil {
return nil, err
}
err = persistence.SetSearchAttributeBool(testSearchAttributeBool, true)
if err != nil {
return nil, err
}
return iwf.SingleNextState(persistenceWorkflowState2Id, nil), nil
}

func (b persistenceWorkflowState1) GetStateOptions() *iwfidl.WorkflowStateOptions {
return nil
persistence.GetDataObject(testDataObjectKey, &do)
persistence.SetSearchAttributeDatetime(testSearchAttributeDatetime, do.Datetime)
persistence.SetSearchAttributeBool(testSearchAttributeBool, true)
return iwf.SingleNextState(persistenceWorkflowState2{}, nil), nil
}

0 comments on commit 877c7ea

Please sign in to comment.