From 55a4d4b621215f15a8595754fca2fb0492e64863 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Wed, 21 Feb 2024 15:08:36 -0800 Subject: [PATCH 1/2] use omitempty for start workflow input --- service/api/service.go | 4 ++-- service/interfaces.go | 18 ++++++++---------- service/interpreter/workflowImpl.go | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/service/api/service.go b/service/api/service.go index 4407a41c..3a9f9264 100644 --- a/service/api/service.go +++ b/service/api/service.go @@ -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, diff --git a/service/interfaces.go b/service/interfaces.go index 5972d033..d0de9f1e 100644 --- a/service/interfaces.go +++ b/service/interfaces.go @@ -1,8 +1,6 @@ package service import ( - "time" - "github.com/indeedeng/iwf/gen/iwfidl" ) @@ -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 { @@ -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 diff --git a/service/interpreter/workflowImpl.go b/service/interpreter/workflowImpl.go index 910dd458..35bccea7 100644 --- a/service/interpreter/workflowImpl.go +++ b/service/interpreter/workflowImpl.go @@ -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}) } @@ -302,7 +302,7 @@ 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, } return nil, provider.NewInterpreterContinueAsNewError(ctx, input) From 2d468fdc5266d71d0f58fe62befc9c69d2139ba1 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Wed, 21 Feb 2024 16:03:50 -0800 Subject: [PATCH 2/2] nix --- service/interpreter/workflowImpl.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/interpreter/workflowImpl.go b/service/interpreter/workflowImpl.go index 35bccea7..50bfa20e 100644 --- a/service/interpreter/workflowImpl.go +++ b/service/interpreter/workflowImpl.go @@ -305,6 +305,10 @@ func InterpreterImpl( 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