Skip to content

Commit

Permalink
Make --wait-for-stage required
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Aug 28, 2024
1 parent 292f8dc commit f828326
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
6 changes: 5 additions & 1 deletion temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2667,14 +2667,15 @@ type TemporalWorkflowUpdateStartCommand struct {
Command cobra.Command
UpdateOptions
PayloadInputOptions
WaitForStage StringEnum
}

func NewTemporalWorkflowUpdateStartCommand(cctx *CommandContext, parent *TemporalWorkflowUpdateCommand) *TemporalWorkflowUpdateStartCommand {
var s TemporalWorkflowUpdateStartCommand
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 {
Expand All @@ -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",
}))
Expand Down
10 changes: 9 additions & 1 deletion temporalcli/commands.workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 17 additions & 14 deletions temporalcli/commands.workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

0 comments on commit f828326

Please sign in to comment.