From 60f35e82934976abbab170c4c8c93487d1890d9b Mon Sep 17 00:00:00 2001 From: Saman Barghi Date: Tue, 25 Apr 2023 16:53:24 -0700 Subject: [PATCH] PR comments --- tests/workflow_test.go | 5 ++- workflow/workflow.go | 11 +----- workflow/workflow_commands.go | 63 +++++++++++------------------------ 3 files changed, 25 insertions(+), 54 deletions(-) diff --git a/tests/workflow_test.go b/tests/workflow_test.go index 2f1d96ae..33719c99 100644 --- a/tests/workflow_test.go +++ b/tests/workflow_test.go @@ -88,16 +88,19 @@ func (s *e2eSuite) TestWorkflowUpdate() { err = s.app.Run([]string{"", "workflow", "update", "--workflow-id", wfr.GetID(), "--run-id", wfr.GetRunID(), "--name", update.FetchAndAdd, "-i", "1", "--first-execution-run-id", wfr.GetRunID()}) s.NoError(err) - // update rejected, when name or update-id is not available + // update rejected, when name is not available err = s.app.Run([]string{"", "workflow", "update", "--workflow-id", "non-existent-ID", "--run-id", wfr.GetRunID(), "-i", "1"}) s.Error(err) + s.ErrorContains(err, "Required flag \"name\" not set") // update rejected, wrong workflowID err = s.app.Run([]string{"", "workflow", "update", "--workflow-id", "non-existent-ID", "--run-id", wfr.GetRunID(), "--name", update.FetchAndAdd, "-i", "1"}) s.Error(err) + s.ErrorContains(err, "update workflow failed") // update rejected, wrong update name err = s.app.Run([]string{"", "workflow", "update", "--workflow-id", wfr.GetID(), "--run-id", wfr.GetRunID(), "--name", "non-existent-name", "-i", "1"}) s.Error(err) + s.ErrorContains(err, "update workflow failed: unknown update") } diff --git a/workflow/workflow.go b/workflow/workflow.go index fab407b3..7e270f0a 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -390,20 +390,11 @@ func NewWorkflowCommands() []*cli.Command { Usage: common.UpdateWorkflowDefinition, UsageText: common.WorkflowUpdateUsageText, Flags: append(common.FlagsForExecution, - &cli.StringFlag{ - Name: common.FlagUpdateWaitPolicy, - Usage: "Wait policy determines which status the client should wait to receive from the server:" + strings.Join(mapKeysToArray(updateWaitPolicyMap), ", "), - Category: common.CategoryMain, - Required: true, - // TODO: Remove these after more wait policies has been added - Hidden: true, - HasBeenSet: true, - Value: "Completed", - }, &cli.StringFlag{ Name: common.FlagName, Usage: common.FlagUpdateHandlerName, Category: common.CategoryMain, + Required: true, }, &cli.StringFlag{ Name: common.FlagUpdateID, diff --git a/workflow/workflow_commands.go b/workflow/workflow_commands.go index 6a897e8b..e042c4fb 100644 --- a/workflow/workflow_commands.go +++ b/workflow/workflow_commands.go @@ -54,9 +54,6 @@ var ( "Signal": enumspb.RESET_REAPPLY_TYPE_SIGNAL, "None": enumspb.RESET_REAPPLY_TYPE_NONE, } - updateWaitPolicyMap = map[string]interface{}{ - "Completed": enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED, - } ) func StartWorkflowBaseArgs(c *cli.Context) ( @@ -1452,40 +1449,23 @@ func UpdateWorkflow(c *cli.Context) error { wid := c.String(common.FlagWorkflowID) rid := c.String(common.FlagRunID) name := c.String(common.FlagName) - uid := c.String(common.FlagUpdateID) first_execution_run_id := c.String(common.FlagUpdateFirstExecutionRunID) args, err := common.UnmarshalInputsFromCLI(c) if err != nil { return err } - waitPolicy, ok := updateWaitPolicyMap[c.String(common.FlagUpdateWaitPolicy)] - if !ok { - return fmt.Errorf("must specify valid wait policy: %v", strings.Join(mapKeysToArray(updateWaitPolicyMap), ", ")) - } - if (len(name) == 0 && len(uid) == 0) || (len(name) > 0 && len(uid) > 0) { - return fmt.Errorf("either %v or %v should be provided", color.Yellow(c, "--%v", common.FlagName), color.Yellow(c, "--%v", common.FlagUpdateID)) - } - - if len(name) > 0 { - request := sdkclient.UpdateWorkflowWithOptionsRequest{ - WorkflowID: wid, - RunID: rid, - UpdateName: name, - Args: args, - FirstExecutionRunID: first_execution_run_id, - // TODO: uncomment when waitPolicy is available - // waitPolicy: waitPolicy, - } - return updateWorkflowHelper(c, &request, waitPolicy) - } else { - // TODO: implement this when GetWorkflowUpdateHandle is available in SDKClient - return fmt.Errorf("Getting update result is not yet implemented") + request := sdkclient.UpdateWorkflowWithOptionsRequest{ + WorkflowID: wid, + RunID: rid, + UpdateName: name, + Args: args, + FirstExecutionRunID: first_execution_run_id, } + return updateWorkflowHelper(c, &request) } -// TODO: remove waitPolicy after it is available in the request -func updateWorkflowHelper(c *cli.Context, request *sdkclient.UpdateWorkflowWithOptionsRequest, waitPolicy interface{}) error { +func updateWorkflowHelper(c *cli.Context, request *sdkclient.UpdateWorkflowWithOptionsRequest) error { ctx, cancel := common.NewContext(c) defer cancel() sdk, err := client.GetSDKClient(c) @@ -1499,22 +1479,19 @@ func updateWorkflowHelper(c *cli.Context, request *sdkclient.UpdateWorkflowWithO return fmt.Errorf("unable to update workflow: %w", err) } - switch waitPolicy { - case enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED: - var valuePtr interface{} - err = workflowUpdateHandle.Get(ctx, &valuePtr) - if err != nil { - return fmt.Errorf("unable to update workflow: %w", err) - } - result := map[string]interface{}{ - "Name": request.UpdateName, - "UpdateID": workflowUpdateHandle.UpdateID(), - "Result": valuePtr, - } - - fmt.Println(color.Green(c, "update workflow succeeded:")) - common.PrettyPrintJSONObject(c, result) + var valuePtr interface{} + err = workflowUpdateHandle.Get(ctx, &valuePtr) + if err != nil { + return fmt.Errorf("update workflow failed: %w", err) + } + result := map[string]interface{}{ + "Name": request.UpdateName, + "UpdateID": workflowUpdateHandle.UpdateID(), + "Result": valuePtr, } + + fmt.Println(color.Green(c, "update workflow succeeded:")) + common.PrettyPrintJSONObject(c, result) return nil }