Skip to content

Commit

Permalink
use omitempty for start workflow input (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Feb 22, 2024
1 parent 84db42f commit bc0b000
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions service/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ func (s *serviceImpl) ApiV1WorkflowStartPost(
IwfWorkflowType: req.GetIwfWorkflowType(),
IwfWorkerUrl: req.GetIwfWorkerUrl(),
StartStateId: req.StartStateId,
StateInput: req.GetStateInput(),
StateOptions: req.GetStateOptions(),
StateInput: req.StateInput,
StateOptions: req.StateOptions,
InitSearchAttributes: initCustomSAs,
Config: workflowConfig,
UseMemoForDataAttributes: useMemo,
Expand Down
18 changes: 8 additions & 10 deletions service/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package service

import (
"time"

"github.com/indeedeng/iwf/gen/iwfidl"
)

Expand All @@ -16,23 +14,21 @@ type (

WaitForCompletionStateExecutionIds []string `json:"waitForCompletionStateExecutionIds,omitempty"`

StateInput iwfidl.EncodedObject `json:"stateInput,omitempty"`
StateInput *iwfidl.EncodedObject `json:"stateInput,omitempty"`

StateOptions iwfidl.WorkflowStateOptions `json:"stateOptions,omitempty"`
StateOptions *iwfidl.WorkflowStateOptions `json:"stateOptions,omitempty"`

InitSearchAttributes []iwfidl.SearchAttribute `json:"initSearchAttributes,omitempty"`

UseMemoForDataAttributes bool `json:"useMemoForDataAttributes"`
UseMemoForDataAttributes bool `json:"useMemoForDataAttributes,omitempty"`

Config iwfidl.WorkflowConfig `json:"config,omitempty"`

// IsResumeFromContinueAsNew indicate this is input for continueAsNew
// when true, will ignore StartStateId, StateInput, StateOptions, InitSearchAttributes
IsResumeFromContinueAsNew bool `json:"isResumeFromContinueAsNew"`

ContinueAsNewInput ContinueAsNewInput `json:"continueAsNewInput"`
IsResumeFromContinueAsNew bool `json:"isResumeFromContinueAsNew,omitempty"`

WorkflowExecutionTimeout time.Duration
ContinueAsNewInput *ContinueAsNewInput `json:"continueAsNewInput,omitempty"`
}

ContinueAsNewInput struct {
Expand Down Expand Up @@ -178,7 +174,9 @@ const (
// ValidateTimerSkipRequest validates if the skip timer request is valid
// return true if it's valid, along with the timer pointer
// use timerIdx if timerId is not empty
func ValidateTimerSkipRequest(stateExeTimerInfos map[string][]*TimerInfo, stateExeId, timerId string, timerIdx int) (*TimerInfo, bool) {
func ValidateTimerSkipRequest(
stateExeTimerInfos map[string][]*TimerInfo, stateExeId, timerId string, timerIdx int,
) (*TimerInfo, bool) {
timerInfos := stateExeTimerInfos[stateExeId]
if len(timerInfos) == 0 {
return nil, false
Expand Down
10 changes: 7 additions & 3 deletions service/interpreter/workflowImpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func InterpreterImpl(
if input.StartStateId != nil {
startingState := iwfidl.StateMovement{
StateId: *input.StartStateId,
StateOptions: &input.StateOptions,
StateInput: &input.StateInput,
StateOptions: input.StateOptions,
StateInput: input.StateInput,
}
stateRequestQueue.AddStateStartRequests([]iwfidl.StateMovement{startingState})
}
Expand Down Expand Up @@ -302,9 +302,13 @@ func InterpreterImpl(
// last update config, do it here because we use input to carry over config, not continueAsNewer query
input.Config = workflowConfiger.Get() // update config to the lastest before continueAsNew to carry over
input.IsResumeFromContinueAsNew = true
input.ContinueAsNewInput = service.ContinueAsNewInput{
input.ContinueAsNewInput = &service.ContinueAsNewInput{
PreviousInternalRunId: provider.GetWorkflowInfo(ctx).WorkflowExecution.RunID,
}
// nix the unused data
input.StateInput = nil
input.StateOptions = nil
input.StartStateId = nil
return nil, provider.NewInterpreterContinueAsNewError(ctx, input)
}
} // end main loop
Expand Down

0 comments on commit bc0b000

Please sign in to comment.