diff --git a/internal/temporalcli/commands.activity.go b/internal/temporalcli/commands.activity.go index 5f6b95421..cfb30ba41 100644 --- a/internal/temporalcli/commands.activity.go +++ b/internal/temporalcli/commands.activity.go @@ -54,6 +54,25 @@ func (c *TemporalActivityStartCommand) run(cctx *CommandContext, args []string) return printActivityExecution(cctx, c.ActivityId, handle.GetRunID(), c.Parent.Namespace) } +func (c *TemporalActivityDeleteCommand) run(cctx *CommandContext, args []string) error { + cl, err := dialClient(cctx, &c.Parent.ClientOptions) + if err != nil { + return err + } + defer cl.Close() + + _, err = cl.WorkflowService().DeleteActivityExecution(cctx, &workflowservice.DeleteActivityExecutionRequest{ + Namespace: c.Parent.Namespace, + ActivityId: c.ActivityId, + RunId: c.RunId, + }) + if err != nil { + return fmt.Errorf("failed deleting activity: %w", err) + } + + return printActivityDeletion(cctx, c.ActivityId, c.RunId, c.Parent.Namespace) +} + func (c *TemporalActivityExecuteCommand) run(cctx *CommandContext, args []string) error { cl, err := dialClient(cctx, &c.Parent.ClientOptions) if err != nil { @@ -123,6 +142,21 @@ func printActivityExecution(cctx *CommandContext, activityID, runID, namespace s }, printer.StructuredOptions{}) } +func printActivityDeletion(cctx *CommandContext, activityID, runID, namespace string) error { + if !cctx.JSONOutput { + cctx.Printer.Println(color.MagentaString("Deleted execution:")) + } + return cctx.Printer.PrintStructured(struct { + ActivityId string `json:"activityId"` + RunId string `json:"runId"` + Namespace string `json:"namespace"` + }{ + ActivityId: activityID, + RunId: runID, + Namespace: namespace, + }, printer.StructuredOptions{}) +} + func buildStartActivityOptions(opts *ActivityStartOptions) (client.StartActivityOptions, error) { o := client.StartActivityOptions{ ID: opts.ActivityId, diff --git a/internal/temporalcli/commands.gen.go b/internal/temporalcli/commands.gen.go index b70bec6be..b5607a1c8 100644 --- a/internal/temporalcli/commands.gen.go +++ b/internal/temporalcli/commands.gen.go @@ -391,16 +391,16 @@ func (v *ActivityStartOptions) BuildFlags(f *pflag.FlagSet) { _ = cobra.MarkFlagRequired(f, "activity-id") f.StringVar(&v.Type, "type", "", "Activity Type name. Required.") _ = cobra.MarkFlagRequired(f, "type") - f.StringVarP(&v.TaskQueue, "task-queue", "t", "", "Activity Task queue. Required.") + f.StringVarP(&v.TaskQueue, "task-queue", "t", "", "Activity task queue. Required.") _ = cobra.MarkFlagRequired(f, "task-queue") v.ScheduleToCloseTimeout = 0 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.") v.ScheduleToStartTimeout = 0 - 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.") + 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.") v.StartToCloseTimeout = 0 - f.Var(&v.StartToCloseTimeout, "start-to-close-timeout", "Maximum time for a single Activity attempt. Either this or \"schedule-to-close-timeout\" is required.") + 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.") v.HeartbeatTimeout = 0 - f.Var(&v.HeartbeatTimeout, "heartbeat-timeout", "Maximum time between successful Worker heartbeats.") + f.Var(&v.HeartbeatTimeout, "heartbeat-timeout", "Maximum time between successful Worker heartbeats. On expiry the current activity attempt fails.") v.RetryInitialInterval = 0 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.") v.RetryMaximumInterval = 0 @@ -466,6 +466,7 @@ func NewTemporalActivityCommand(cctx *CommandContext, parent *TemporalCommand) * s.Command.AddCommand(&NewTemporalActivityCancelCommand(cctx, &s).Command) s.Command.AddCommand(&NewTemporalActivityCompleteCommand(cctx, &s).Command) s.Command.AddCommand(&NewTemporalActivityCountCommand(cctx, &s).Command) + s.Command.AddCommand(&NewTemporalActivityDeleteCommand(cctx, &s).Command) s.Command.AddCommand(&NewTemporalActivityDescribeCommand(cctx, &s).Command) s.Command.AddCommand(&NewTemporalActivityExecuteCommand(cctx, &s).Command) s.Command.AddCommand(&NewTemporalActivityFailCommand(cctx, &s).Command) @@ -572,6 +573,33 @@ func NewTemporalActivityCountCommand(cctx *CommandContext, parent *TemporalActiv return &s } +type TemporalActivityDeleteCommand struct { + Parent *TemporalActivityCommand + Command cobra.Command + ActivityReferenceOptions +} + +func NewTemporalActivityDeleteCommand(cctx *CommandContext, parent *TemporalActivityCommand) *TemporalActivityDeleteCommand { + var s TemporalActivityDeleteCommand + s.Parent = parent + s.Command.DisableFlagsInUseLine = true + s.Command.Use = "delete [flags]" + s.Command.Short = "Forcefully end a Standalone Activity (Experimental)" + if hasHighlighting { + 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." + } else { + 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." + } + s.Command.Args = cobra.NoArgs + s.ActivityReferenceOptions.BuildFlags(s.Command.Flags()) + s.Command.Run = func(c *cobra.Command, args []string) { + if err := s.run(cctx, args); err != nil { + cctx.Options.Fail(err) + } + } + return &s +} + type TemporalActivityDescribeCommand struct { Parent *TemporalActivityCommand Command cobra.Command @@ -815,9 +843,9 @@ func NewTemporalActivityStartCommand(cctx *CommandContext, parent *TemporalActiv s.Command.Use = "start [flags]" s.Command.Short = "Start a new Standalone Activity (Experimental)" if hasHighlighting { - 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" + 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" } else { - 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```" + 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```" } s.Command.Args = cobra.NoArgs s.ActivityStartOptions.BuildFlags(s.Command.Flags()) diff --git a/internal/temporalcli/commands.yaml b/internal/temporalcli/commands.yaml index d8cf4ee95..f7526e8ef 100644 --- a/internal/temporalcli/commands.yaml +++ b/internal/temporalcli/commands.yaml @@ -716,6 +716,21 @@ commands: Reason for termination. Defaults to a message with the current user's name. + - name: temporal activity delete + summary: Forcefully end a Standalone Activity (Experimental) + description: | + Delete a Standalone Activity. + + ``` + temporal activity delete \ + --activity-id YourActivityId \ + --run-id YourRunId + ``` + + Activity code cannot see or respond to deletions. + option-sets: + - activity-reference + - name: temporal batch summary: Manage running batch jobs description: |