Skip to content

Commit bd8c84b

Browse files
authored
Implement activity delete command (#963)
## What was changed Add `temporal activity delete` command for deleting a standalone activity. ## Why? CLI work for this server PR: temporalio/temporal#9515 ## Checklist 1. Closes: NA 2. How was this tested: NA 3. Any docs updates needed? NA
1 parent ec36926 commit bd8c84b

3 files changed

Lines changed: 83 additions & 6 deletions

File tree

internal/temporalcli/commands.activity.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ func (c *TemporalActivityStartCommand) run(cctx *CommandContext, args []string)
5454
return printActivityExecution(cctx, c.ActivityId, handle.GetRunID(), c.Parent.Namespace)
5555
}
5656

57+
func (c *TemporalActivityDeleteCommand) run(cctx *CommandContext, args []string) error {
58+
cl, err := dialClient(cctx, &c.Parent.ClientOptions)
59+
if err != nil {
60+
return err
61+
}
62+
defer cl.Close()
63+
64+
_, err = cl.WorkflowService().DeleteActivityExecution(cctx, &workflowservice.DeleteActivityExecutionRequest{
65+
Namespace: c.Parent.Namespace,
66+
ActivityId: c.ActivityId,
67+
RunId: c.RunId,
68+
})
69+
if err != nil {
70+
return fmt.Errorf("failed deleting activity: %w", err)
71+
}
72+
73+
return printActivityDeletion(cctx, c.ActivityId, c.RunId, c.Parent.Namespace)
74+
}
75+
5776
func (c *TemporalActivityExecuteCommand) run(cctx *CommandContext, args []string) error {
5877
cl, err := dialClient(cctx, &c.Parent.ClientOptions)
5978
if err != nil {
@@ -123,6 +142,21 @@ func printActivityExecution(cctx *CommandContext, activityID, runID, namespace s
123142
}, printer.StructuredOptions{})
124143
}
125144

145+
func printActivityDeletion(cctx *CommandContext, activityID, runID, namespace string) error {
146+
if !cctx.JSONOutput {
147+
cctx.Printer.Println(color.MagentaString("Deleted execution:"))
148+
}
149+
return cctx.Printer.PrintStructured(struct {
150+
ActivityId string `json:"activityId"`
151+
RunId string `json:"runId"`
152+
Namespace string `json:"namespace"`
153+
}{
154+
ActivityId: activityID,
155+
RunId: runID,
156+
Namespace: namespace,
157+
}, printer.StructuredOptions{})
158+
}
159+
126160
func buildStartActivityOptions(opts *ActivityStartOptions) (client.StartActivityOptions, error) {
127161
o := client.StartActivityOptions{
128162
ID: opts.ActivityId,

internal/temporalcli/commands.gen.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,16 @@ func (v *ActivityStartOptions) BuildFlags(f *pflag.FlagSet) {
391391
_ = cobra.MarkFlagRequired(f, "activity-id")
392392
f.StringVar(&v.Type, "type", "", "Activity Type name. Required.")
393393
_ = cobra.MarkFlagRequired(f, "type")
394-
f.StringVarP(&v.TaskQueue, "task-queue", "t", "", "Activity Task queue. Required.")
394+
f.StringVarP(&v.TaskQueue, "task-queue", "t", "", "Activity task queue. Required.")
395395
_ = cobra.MarkFlagRequired(f, "task-queue")
396396
v.ScheduleToCloseTimeout = 0
397397
f.Var(&v.ScheduleToCloseTimeout, "schedule-to-close-timeout", "Maximum time for the Activity Execution, including all retries. Either this or \"start-to-close-timeout\" is required.")
398398
v.ScheduleToStartTimeout = 0
399-
f.Var(&v.ScheduleToStartTimeout, "schedule-to-start-timeout", "Maximum time an Activity task can stay in a task queue before a Worker picks it up.")
399+
f.Var(&v.ScheduleToStartTimeout, "schedule-to-start-timeout", "Maximum time an Activity task can stay in a task queue before a Worker picks it up. On expiry it results in a non-retryable failure and no further attempts are scheduled.")
400400
v.StartToCloseTimeout = 0
401-
f.Var(&v.StartToCloseTimeout, "start-to-close-timeout", "Maximum time for a single Activity attempt. Either this or \"schedule-to-close-timeout\" is required.")
401+
f.Var(&v.StartToCloseTimeout, "start-to-close-timeout", "Maximum time for a single Activity attempt. On expiry a new attempt may be scheduled if permitted by the retry policy and schedule-to-close timeout. Either this or \"schedule-to-close-timeout\" is required.")
402402
v.HeartbeatTimeout = 0
403-
f.Var(&v.HeartbeatTimeout, "heartbeat-timeout", "Maximum time between successful Worker heartbeats.")
403+
f.Var(&v.HeartbeatTimeout, "heartbeat-timeout", "Maximum time between successful Worker heartbeats. On expiry the current activity attempt fails.")
404404
v.RetryInitialInterval = 0
405405
f.Var(&v.RetryInitialInterval, "retry-initial-interval", "Interval of the first retry. If \"retry-backoff-coefficient\" is 1.0, it is used for all retries.")
406406
v.RetryMaximumInterval = 0
@@ -466,6 +466,7 @@ func NewTemporalActivityCommand(cctx *CommandContext, parent *TemporalCommand) *
466466
s.Command.AddCommand(&NewTemporalActivityCancelCommand(cctx, &s).Command)
467467
s.Command.AddCommand(&NewTemporalActivityCompleteCommand(cctx, &s).Command)
468468
s.Command.AddCommand(&NewTemporalActivityCountCommand(cctx, &s).Command)
469+
s.Command.AddCommand(&NewTemporalActivityDeleteCommand(cctx, &s).Command)
469470
s.Command.AddCommand(&NewTemporalActivityDescribeCommand(cctx, &s).Command)
470471
s.Command.AddCommand(&NewTemporalActivityExecuteCommand(cctx, &s).Command)
471472
s.Command.AddCommand(&NewTemporalActivityFailCommand(cctx, &s).Command)
@@ -572,6 +573,33 @@ func NewTemporalActivityCountCommand(cctx *CommandContext, parent *TemporalActiv
572573
return &s
573574
}
574575

576+
type TemporalActivityDeleteCommand struct {
577+
Parent *TemporalActivityCommand
578+
Command cobra.Command
579+
ActivityReferenceOptions
580+
}
581+
582+
func NewTemporalActivityDeleteCommand(cctx *CommandContext, parent *TemporalActivityCommand) *TemporalActivityDeleteCommand {
583+
var s TemporalActivityDeleteCommand
584+
s.Parent = parent
585+
s.Command.DisableFlagsInUseLine = true
586+
s.Command.Use = "delete [flags]"
587+
s.Command.Short = "Forcefully end a Standalone Activity (Experimental)"
588+
if hasHighlighting {
589+
s.Command.Long = "Delete a Standalone Activity.\n\n\x1b[1mtemporal activity delete \\\n --activity-id YourActivityId \\\n --run-id YourRunId\x1b[0m\n\nActivity code cannot see or respond to deletions."
590+
} else {
591+
s.Command.Long = "Delete a Standalone Activity.\n\n```\ntemporal activity delete \\\n --activity-id YourActivityId \\\n --run-id YourRunId\n```\n\nActivity code cannot see or respond to deletions."
592+
}
593+
s.Command.Args = cobra.NoArgs
594+
s.ActivityReferenceOptions.BuildFlags(s.Command.Flags())
595+
s.Command.Run = func(c *cobra.Command, args []string) {
596+
if err := s.run(cctx, args); err != nil {
597+
cctx.Options.Fail(err)
598+
}
599+
}
600+
return &s
601+
}
602+
575603
type TemporalActivityDescribeCommand struct {
576604
Parent *TemporalActivityCommand
577605
Command cobra.Command
@@ -815,9 +843,9 @@ func NewTemporalActivityStartCommand(cctx *CommandContext, parent *TemporalActiv
815843
s.Command.Use = "start [flags]"
816844
s.Command.Short = "Start a new Standalone Activity (Experimental)"
817845
if hasHighlighting {
818-
s.Command.Long = "Start a new Standalone Activity. Outputs the Activity ID and\nRun ID.\n\n\x1b[1mtemporal activity start \\\n --activity-id YourActivityId \\\n --type YourActivity \\\n --task-queue YourTaskQueue \\\n --schedule-to-close-timeout 5m \\\n --input '{\"some-key\": \"some-value\"}'\x1b[0m"
846+
s.Command.Long = "Start a new Standalone Activity. Outputs the Activity ID and\nRun ID.\n\n\x1b[1mtemporal activity start \\\n --activity-id YourActivityId \\\n --type YourActivity \\\n --task-queue YourTaskQueue \\\n --start-to-close-timeout 5m \\\n --input '{\"some-key\": \"some-value\"}'\x1b[0m"
819847
} else {
820-
s.Command.Long = "Start a new Standalone Activity. Outputs the Activity ID and\nRun ID.\n\n```\ntemporal activity start \\\n --activity-id YourActivityId \\\n --type YourActivity \\\n --task-queue YourTaskQueue \\\n --schedule-to-close-timeout 5m \\\n --input '{\"some-key\": \"some-value\"}'\n```"
848+
s.Command.Long = "Start a new Standalone Activity. Outputs the Activity ID and\nRun ID.\n\n```\ntemporal activity start \\\n --activity-id YourActivityId \\\n --type YourActivity \\\n --task-queue YourTaskQueue \\\n --start-to-close-timeout 5m \\\n --input '{\"some-key\": \"some-value\"}'\n```"
821849
}
822850
s.Command.Args = cobra.NoArgs
823851
s.ActivityStartOptions.BuildFlags(s.Command.Flags())

internal/temporalcli/commands.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,21 @@ commands:
716716
Reason for termination.
717717
Defaults to a message with the current user's name.
718718
719+
- name: temporal activity delete
720+
summary: Forcefully end a Standalone Activity (Experimental)
721+
description: |
722+
Delete a Standalone Activity.
723+
724+
```
725+
temporal activity delete \
726+
--activity-id YourActivityId \
727+
--run-id YourRunId
728+
```
729+
730+
Activity code cannot see or respond to deletions.
731+
option-sets:
732+
- activity-reference
733+
719734
- name: temporal batch
720735
summary: Manage running batch jobs
721736
description: |

0 commit comments

Comments
 (0)