Skip to content

Commit c10019c

Browse files
Add iwf.WorkflowStateDefaultsNoWaitUntil (#62)
1 parent be3de1a commit c10019c

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

integ/no_startstate_workflow.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func (b noStartStateWorkflow) TestRPC(ctx iwf.WorkflowContext, input iwf.Object,
2929
}
3030

3131
type noStartStateWorkflowState1 struct {
32-
iwf.WorkflowStateDefaults
33-
iwf.NoWaitUntil
32+
iwf.WorkflowStateDefaultsNoWaitUntil
3433
}
3534

3635
func (b noStartStateWorkflowState1) Execute(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {

integ/skip_wait_until_state1.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
)
66

77
type skipWaitUntilState1 struct {
8-
iwf.WorkflowStateDefaults
9-
iwf.NoWaitUntil
8+
iwf.WorkflowStateDefaultsNoWaitUntil
109
}
1110

1211
func (b skipWaitUntilState1) Execute(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {

integ/skip_wait_until_state2.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
)
66

77
type skipWaitUntilState2 struct {
8-
iwf.WorkflowStateDefaults
9-
iwf.NoWaitUntil
8+
iwf.WorkflowStateDefaultsNoWaitUntil
109
}
1110

1211
func (b skipWaitUntilState2) Execute(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {

integ/workflow_uncompleted_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestWorkflowTimeout(t *testing.T) {
2929
assert.Nil(t, out)
3030
assert.Equal(t, err, err2)
3131

32-
assert.Equal(t, "workflow is not completed succesfully, closedStatus: TIMEOUT, failedErrorType(applies if failed as closedStatus):<nil>, error message:<nil>", err.Error())
32+
assert.Equal(t, "workflow is not completed successfully, closedStatus: TIMEOUT, failedErrorType(applies if failed as closedStatus):<nil>, error message:<nil>", err.Error())
3333
}
3434

3535
func TestWorkflowCancel(t *testing.T) {
@@ -51,7 +51,7 @@ func TestWorkflowCancel(t *testing.T) {
5151
assert.Nil(t, out)
5252
assert.Equal(t, err, err2)
5353

54-
assert.Equal(t, "workflow is not completed succesfully, closedStatus: CANCELED, failedErrorType(applies if failed as closedStatus):<nil>, error message:<nil>", err.Error())
54+
assert.Equal(t, "workflow is not completed successfully, closedStatus: CANCELED, failedErrorType(applies if failed as closedStatus):<nil>, error message:<nil>", err.Error())
5555
}
5656

5757
func TestForceFailWorkflow(t *testing.T) {
@@ -69,7 +69,7 @@ func TestForceFailWorkflow(t *testing.T) {
6969
out, err2 := client.GetComplexWorkflowResults(context.Background(), wfId, "")
7070
assert.Nil(t, out)
7171
assert.Equal(t, err, err2)
72-
assert.Equal(t, "workflow is not completed succesfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_DECISION_FAILING_WORKFLOW_ERROR_TYPE, error message:<nil>", err.Error())
72+
assert.Equal(t, "workflow is not completed successfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_DECISION_FAILING_WORKFLOW_ERROR_TYPE, error message:<nil>", err.Error())
7373

7474
var output string
7575
err = wErr.GetStateResult(0, &output)
@@ -95,7 +95,7 @@ func TestStateApiFailWorkflow(t *testing.T) {
9595
assert.Nil(t, out)
9696
assert.Equal(t, err, err2)
9797

98-
assert.True(t, strings.Contains(err.Error(), "workflow is not completed succesfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, error message:statusCode: 400, responseBody: {\"error\":\"error message:test api failing"))
98+
assert.True(t, strings.Contains(err.Error(), "workflow is not completed successfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, error message:statusCode: 400, responseBody: {\"error\":\"error message:test api failing"))
9999
}
100100

101101
func TestStateApiTimeoutWorkflow(t *testing.T) {
@@ -112,7 +112,7 @@ func TestStateApiTimeoutWorkflow(t *testing.T) {
112112

113113
fmt.Println(err)
114114

115-
expectedMsg := "workflow is not completed succesfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, error message:activity error (type: StateApiWaitUntil, scheduledEventID: 9, startedEventID: 10, identity: ): activity StartToClose timeout (type: StartToClose)"
115+
expectedMsg := "workflow is not completed successfully, closedStatus: FAILED, failedErrorType(applies if failed as closedStatus):STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, error message:activity error (type: StateApiWaitUntil, scheduledEventID: 9, startedEventID: 10, identity: ): activity StartToClose timeout (type: StartToClose)"
116116
assert.Equal(t, expectedMsg, err.Error())
117117

118118
out, err2 := client.GetComplexWorkflowResults(context.Background(), wfId, "")

iwf/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (w *WorkflowUncompletedError) Error() string {
207207
if w.ErrorMessage != nil {
208208
message = fmt.Sprintf("%v", *w.ErrorMessage)
209209
}
210-
return fmt.Sprintf("workflow is not completed succesfully, closedStatus: %v, failedErrorType(applies if failed as closedStatus):%v, error message:%v",
210+
return fmt.Sprintf("workflow is not completed successfully, closedStatus: %v, failedErrorType(applies if failed as closedStatus):%v, error message:%v",
211211
w.ClosedStatus, errTypeMsg, message)
212212
}
213213

iwf/workflow_state.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type WorkflowState interface {
1818
// 3. In case of dynamic workflow state implementation, return customized values instead of using empty string
1919
GetStateId() string
2020

21-
// WaitUntil is the method to set up commands set up to wait for, before `Execute` API is invoked
21+
// WaitUntil is the method to set up commands set up to wait for, before `Execute` API is invoked.
22+
// It's optional -- use iwf.WorkflowStateDefaultsNoWaitUntil or iwf.NoWaitUntil to skip this step( Execute will be invoked instead)
2223
//
2324
// ctx the context info of this API invocation, like workflow start time, workflowId, etc
2425
// input the state input
@@ -33,7 +34,7 @@ type WorkflowState interface {
3334
///
3435
WaitUntil(ctx WorkflowContext, input Object, persistence Persistence, communication Communication) (*CommandRequest, error)
3536

36-
// Execute is the method to execute and decide what to do next
37+
// Execute is the method to execute and decide what to do next. Invoke after commands from WaitUntil are completed, or there is WaitUntil is not implemented for the state.
3738
//
3839
// ctx the context info of this API invocation, like workflow start time, workflowId, etc
3940
// input the state input
@@ -74,6 +75,18 @@ type WorkflowStateDefaults struct {
7475
DefaultStateOptions
7576
}
7677

78+
// WorkflowStateDefaultsNoWaitUntil is a convenient struct to put into your state implementation to save the boilerplate code. Eg:
79+
// Example usage:
80+
//
81+
// type myStateImpl struct{
82+
// WorkflowStateDefaultsNoWaitUntil
83+
// }
84+
type WorkflowStateDefaultsNoWaitUntil struct {
85+
DefaultStateId
86+
DefaultStateOptions
87+
NoWaitUntil
88+
}
89+
7790
type DefaultStateId struct{}
7891

7992
func (d DefaultStateId) GetStateId() string {
@@ -107,7 +120,7 @@ func ShouldSkipWaitUntilAPI(state WorkflowState) bool {
107120

108121
for i := 0; i < t.NumField(); i++ {
109122
field := t.Field(i)
110-
if field.Type.String() == "iwf.NoWaitUntil" {
123+
if field.Type.String() == "iwf.NoWaitUntil" || field.Type.String() == "iwf.WorkflowStateDefaultsNoWaitUntil" {
111124
return true
112125
}
113126
}

0 commit comments

Comments
 (0)