Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samanbarghi committed Apr 25, 2023
1 parent c3b8637 commit 60f35e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 54 deletions.
5 changes: 4 additions & 1 deletion tests/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
11 changes: 1 addition & 10 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 20 additions & 43 deletions workflow/workflow_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) (
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 60f35e8

Please sign in to comment.