diff --git a/temporalcli/commands.gen.go b/temporalcli/commands.gen.go index a864c8a3..36c5da7a 100644 --- a/temporalcli/commands.gen.go +++ b/temporalcli/commands.gen.go @@ -2667,6 +2667,7 @@ type TemporalWorkflowUpdateStartCommand struct { Command cobra.Command UpdateOptions PayloadInputOptions + WaitForStage StringEnum } func NewTemporalWorkflowUpdateStartCommand(cctx *CommandContext, parent *TemporalWorkflowUpdateCommand) *TemporalWorkflowUpdateStartCommand { @@ -2674,7 +2675,7 @@ func NewTemporalWorkflowUpdateStartCommand(cctx *CommandContext, parent *Tempora s.Parent = parent s.Command.DisableFlagsInUseLine = true s.Command.Use = "start [flags]" - s.Command.Short = "Send an Update and wait for it to be accepted" + s.Command.Short = "Send an Update and wait for it to be accepted or rejected" if hasHighlighting { s.Command.Long = "Send a message to a Workflow Execution to invoke an Update handler, and wait for\nthe update to be accepted or rejected. You can subsequently wait for the update\nto complete by using \x1b[1mtemporal workflow update execute\x1b[0m.\n\n\x1b[1mtemporal workflow update start \\\n --workflow-id YourWorkflowId \\\n --name YourUpdate \\\n --input '{\"some-key\": \"some-value\"}'\x1b[0m" } else { @@ -2683,6 +2684,9 @@ func NewTemporalWorkflowUpdateStartCommand(cctx *CommandContext, parent *Tempora s.Command.Args = cobra.NoArgs s.UpdateOptions.buildFlags(cctx, s.Command.Flags()) s.PayloadInputOptions.buildFlags(cctx, s.Command.Flags()) + s.WaitForStage = NewStringEnum([]string{"accepted"}, "") + s.Command.Flags().Var(&s.WaitForStage, "wait-for-stage", "Update stage to wait for. The only option is `accepted`, but this option is required. This is to allow a future version of the CLI to choose a default value. Accepted values: accepted. Required.") + _ = cobra.MarkFlagRequired(s.Command.Flags(), "wait-for-stage") s.Command.Flags().SetNormalizeFunc(aliasNormalizer(map[string]string{ "type": "name", })) diff --git a/temporalcli/commands.workflow.go b/temporalcli/commands.workflow.go index 535b62b6..66d48eb4 100644 --- a/temporalcli/commands.workflow.go +++ b/temporalcli/commands.workflow.go @@ -187,7 +187,15 @@ func (c *TemporalWorkflowTerminateCommand) run(cctx *CommandContext, _ []string) } func (c *TemporalWorkflowUpdateStartCommand) run(cctx *CommandContext, args []string) error { - return workflowUpdateHelper(cctx, c.Parent.Parent.ClientOptions, c.PayloadInputOptions, c.UpdateOptions, client.WorkflowUpdateStageAccepted) + waitForStage := client.WorkflowUpdateStageUnspecified + switch c.WaitForStage.Value { + case "accepted": + waitForStage = client.WorkflowUpdateStageAccepted + } + if waitForStage != client.WorkflowUpdateStageAccepted { + return fmt.Errorf("invalid wait for stage: %v, valid values are: 'accepted'", c.WaitForStage) + } + return workflowUpdateHelper(cctx, c.Parent.Parent.ClientOptions, c.PayloadInputOptions, c.UpdateOptions, waitForStage) } func (c *TemporalWorkflowUpdateExecuteCommand) run(cctx *CommandContext, args []string) error { diff --git a/temporalcli/commands.workflow_test.go b/temporalcli/commands.workflow_test.go index b0d15847..1f2c34b1 100644 --- a/temporalcli/commands.workflow_test.go +++ b/temporalcli/commands.workflow_test.go @@ -464,25 +464,28 @@ func (t workflowUpdateTest) testWorkflowUpdateHelper() { t.s.ContainsOnSameLine(res.Stdout.String(), "UpdateID", strconv.Itoa(input)) t.s.ContainsOnSameLine(res.Stdout.String(), "Result", strconv.Itoa(3*input)) - verb := "" if t.useStart { - verb = "start" - } else { - verb = "execute" - } + // update rejected, name not supplied + res = t.s.Execute("workflow", "update", "start", "--wait-for-stage", "accepted", "--address", t.s.Address(), "-w", run.GetID(), "-i", strconv.Itoa(input)) + t.s.ErrorContains(res.Err, "required flag(s) \"name\" not set") + + // update rejected, wrong workflowID + res = t.s.Execute("workflow", "update", "start", "--wait-for-stage", "accepted", "--address", t.s.Address(), "-w", "nonexistent-wf-id", "--name", updateName, "-i", strconv.Itoa(input)) + t.s.ErrorContains(res.Err, "unable to update workflow") - // update rejected, name not supplied - res = t.s.Execute("workflow", "update", verb, "--address", t.s.Address(), "-w", run.GetID(), "-i", strconv.Itoa(input)) - t.s.ErrorContains(res.Err, "required flag(s) \"name\" not set") + // TODO: wrong update name is not currently an error when using `update start` (?!) + } else { + // update rejected, name not supplied + res = t.s.Execute("workflow", "update", "execute", "--address", t.s.Address(), "-w", run.GetID(), "-i", strconv.Itoa(input)) + t.s.ErrorContains(res.Err, "required flag(s) \"name\" not set") - // update rejected, wrong workflowID - res = t.s.Execute("workflow", "update", verb, "--address", t.s.Address(), "-w", "nonexistent-wf-id", "--name", updateName, "-i", strconv.Itoa(input)) - t.s.ErrorContains(res.Err, "unable to update workflow") + // update rejected, wrong workflowID + res = t.s.Execute("workflow", "update", "execute", "--address", t.s.Address(), "-w", "nonexistent-wf-id", "--name", updateName, "-i", strconv.Itoa(input)) + t.s.ErrorContains(res.Err, "unable to update workflow") - if verb == "execute" { // update rejected, wrong update name // This is not currently an error when using `update start`: the SDK accepts the update before checking whether a handler exists. - res = t.s.Execute("workflow", "update", verb, "--address", t.s.Address(), "-w", run.GetID(), "--name", "nonexistent-update-name", "-i", strconv.Itoa(input)) + res = t.s.Execute("workflow", "update", "execute", "--address", t.s.Address(), "-w", run.GetID(), "--name", "nonexistent-update-name", "-i", strconv.Itoa(input)) t.s.ErrorContains(res.Err, "unable to update workflow") } } @@ -494,7 +497,7 @@ func (t workflowUpdateTest) execute(args ...string) *CommandResult { if t.useStart { // Test `update start` by confirming that we can start the update and // then use `update execute` to wait for it to complete. - startArgs := append([]string{"workflow", "update", "start"}, args[3:]...) + startArgs := append([]string{"workflow", "update", "start", "--wait-for-stage", "accepted"}, args[3:]...) res := t.s.Execute(startArgs...) t.s.NoError(res.Err) workflowID, updateID, name := t.extractWorkflowIDUpdateIDAndUpdateName(args, res.Stdout.String()) diff --git a/temporalcli/commandsmd/commands.md b/temporalcli/commandsmd/commands.md index 09a29bad..532c095b 100644 --- a/temporalcli/commandsmd/commands.md +++ b/temporalcli/commandsmd/commands.md @@ -2576,5 +2576,12 @@ temporal workflow update start \ #### Options +* `--wait-for-stage` (string-enum) - + Update stage to wait for. + The only option is `accepted`, but this option is required. This is to allow + a future version of the CLI to choose a default value. + Options: accepted. + Required. + Includes options set for [update](#options-set-for-update). Includes options set for [payload input](#options-set-for-payload-input).