-
Notifications
You must be signed in to change notification settings - Fork 96
fix: activity pause,unpause,reset accept activity type OR activity id #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b916835
e53f3e5
85c244b
48dc88b
fb656f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| package temporalcli | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/mattn/go-isatty" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
@@ -473,10 +475,35 @@ func NewTemporalActivityFailCommand(cctx *CommandContext, parent *TemporalActivi | |
| return &s | ||
| } | ||
|
|
||
| type ActivityReferenceOptions struct { | ||
| ActivityId string | ||
| ActivityType string | ||
| } | ||
|
|
||
| func (v *ActivityReferenceOptions) buildFlags(_ *CommandContext, f *pflag.FlagSet, activityType string, onlyWithoutQuery bool) { | ||
| f.StringVarP(&v.ActivityId, "activity-id", "a", "", fmt.Sprintf("Activity ID to %s.", activityType)) | ||
| if onlyWithoutQuery { | ||
| f.StringVarP(&v.ActivityType, "activity-type", "g", "", fmt.Sprintf("Activity Type to %s. Can only be used without --query.", activityType)) | ||
| } else { | ||
| f.StringVarP(&v.ActivityType, "activity-type", "g", "", fmt.Sprintf("Activity Type to %s.", activityType)) | ||
| } | ||
| } | ||
|
|
||
| func (v *ActivityReferenceOptions) validateFlags() error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't add code to this code-generated file, it'd get removed on regen. Rather, add in another file (or maybe better, do not add methods to generated structures beyond the run method needed on command, but make simple utility functions that accept them).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the cc @ychebotarev |
||
| if v.ActivityId != "" && v.ActivityType != "" { | ||
| return fmt.Errorf("either Activity Type or Activity Id, but not both") | ||
| } | ||
| if v.ActivityId == "" && v.ActivityType == "" { | ||
| return fmt.Errorf("either Activity Type or Activity Id, but not both") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| type TemporalActivityPauseCommand struct { | ||
| Parent *TemporalActivityCommand | ||
| Command cobra.Command | ||
| WorkflowReferenceOptions | ||
| ActivityReferenceOptions | ||
| ActivityId string | ||
| ActivityType string | ||
| Identity string | ||
|
|
@@ -494,10 +521,9 @@ func NewTemporalActivityPauseCommand(cctx *CommandContext, parent *TemporalActiv | |
| s.Command.Long = "Pause an Activity.\n\nIf the Activity is not currently running (e.g. because it previously\nfailed), it will not be run again until it is unpaused.\n\nHowever, if the Activity is currently running, it will run to completion.\nIf the Activity is on its last retry attempt and fails, the failure will\nbe returned to the caller, just as if the Activity had not been paused.\n\nActivities can be specified by their Activity ID or Activity Type.\nOne of those parameters must be provided. If both are provided - Activity\nType will be used, and Activity ID will be ignored.\n\nSpecify the Activity and Workflow IDs:\n\n```\ntemporal activity pause \\\n --activity-id YourActivityId \\\n --workflow-id YourWorkflowId\n```" | ||
| } | ||
| s.Command.Args = cobra.NoArgs | ||
| s.Command.Flags().StringVarP(&s.ActivityId, "activity-id", "a", "", "Activity ID to pause.") | ||
| s.Command.Flags().StringVarP(&s.ActivityType, "activity-type", "g", "", "Activity Type to pause.") | ||
| s.Command.Flags().StringVar(&s.Identity, "identity", "", "Identity of the user submitting this request.") | ||
| s.WorkflowReferenceOptions.buildFlags(cctx, s.Command.Flags()) | ||
| s.ActivityReferenceOptions.buildFlags(cctx, s.Command.Flags(), "pause", false) | ||
| s.Command.Run = func(c *cobra.Command, args []string) { | ||
| if err := s.run(cctx, args); err != nil { | ||
| cctx.Options.Fail(err) | ||
|
|
@@ -510,6 +536,7 @@ type TemporalActivityResetCommand struct { | |
| Parent *TemporalActivityCommand | ||
| Command cobra.Command | ||
| WorkflowReferenceOptions | ||
| ActivityReferenceOptions | ||
| ActivityId string | ||
| ActivityType string | ||
| Identity string | ||
|
|
@@ -529,12 +556,11 @@ func NewTemporalActivityResetCommand(cctx *CommandContext, parent *TemporalActiv | |
| s.Command.Long = "Resetting an activity resets both the number of attempts and the activity\ntimeout.\n\nIf activity is paused and 'keep_paused' flag is not provided - it will be\nunpaused.\nIf activity is paused and 'keep_paused' flag is provided - it will stay\npaused.\nIf activity is waiting for the retry, is will be rescheduled immediately.\nIf the 'reset_heartbeats' flag is set, the activity heartbeat timer and\nheartbeats will be reset.\n\nActivities can be specified by their Activity ID or Activity Type.\nOne of those parameters must be provided. If both are provided - Activity\nType will be used, and Activity ID will be ignored.\n\nSpecify the Activity Type of ID and Workflow IDs:\n\n```\ntemporal activity reset \\\n --activity-id YourActivityId \\\n --workflow-id YourWorkflowId\n --keep-paused\n --reset-heartbeats\n```" | ||
| } | ||
| s.Command.Args = cobra.NoArgs | ||
| s.Command.Flags().StringVarP(&s.ActivityId, "activity-id", "a", "", "Activity ID to pause.") | ||
| s.Command.Flags().StringVarP(&s.ActivityType, "activity-type", "g", "", "Activity Type to pause.") | ||
| s.Command.Flags().StringVar(&s.Identity, "identity", "", "Identity of the user submitting this request.") | ||
| s.Command.Flags().BoolVar(&s.KeepPaused, "keep-paused", false, "If activity was paused - it will stay paused.") | ||
| s.Command.Flags().BoolVar(&s.ResetHeartbeats, "reset-heartbeats", false, "Reset the Activity's heartbeat.") | ||
| s.WorkflowReferenceOptions.buildFlags(cctx, s.Command.Flags()) | ||
| s.ActivityReferenceOptions.buildFlags(cctx, s.Command.Flags(), "reset", false) | ||
| s.Command.Run = func(c *cobra.Command, args []string) { | ||
| if err := s.run(cctx, args); err != nil { | ||
| cctx.Options.Fail(err) | ||
|
|
@@ -547,6 +573,7 @@ type TemporalActivityUnpauseCommand struct { | |
| Parent *TemporalActivityCommand | ||
| Command cobra.Command | ||
| SingleWorkflowOrBatchOptions | ||
| ActivityReferenceOptions | ||
| ActivityId string | ||
| ActivityType string | ||
| Identity string | ||
|
|
@@ -568,15 +595,14 @@ func NewTemporalActivityUnpauseCommand(cctx *CommandContext, parent *TemporalAct | |
| s.Command.Long = "Re-schedule a previously-paused Activity for execution.\n\nIf the Activity is not running and is past its retry timeout, it will be\nscheduled immediately. Otherwise, it will be scheduled after its retry\ntimeout expires.\n\nUse `--reset-attempts` to reset the number of previous run attempts to\nzero. For example, if an Activity is near the maximum number of attempts\nN specified in its retry policy, `--reset-attempts` will allow the\nActivity to be retried another N times after unpausing.\n\nUse `--reset-heartbeat` to reset the Activity's heartbeats.\n\nActivities can be specified by their Activity ID or Activity Type.\nOne of those parameters must be provided. If both are provided - Activity\nType will be used, and Activity ID will be ignored.\n\nActivities can be unpaused in bulk via a visibility Query list filter:\n\n```\ntemporal activity unpause \\\n --query YourQuery \\\n --reason YourReasonForTermination\n```\n\n\nSpecify the Activity ID or Type and Workflow IDs:\n\n```\ntemporal activity unpause \\\n --activity-id YourActivityId \\\n --workflow-id YourWorkflowId\n --reset-attempts\n --reset-heartbeats\n```" | ||
| } | ||
| s.Command.Args = cobra.NoArgs | ||
| s.Command.Flags().StringVarP(&s.ActivityId, "activity-id", "a", "", "Activity ID to unpause. Can only be used without --query.") | ||
| s.Command.Flags().StringVarP(&s.ActivityType, "activity-type", "g", "", "Activity Type to unpause.") | ||
| s.Command.Flags().StringVar(&s.Identity, "identity", "", "Identity of the user submitting this request.") | ||
| s.Command.Flags().BoolVar(&s.ResetAttempts, "reset-attempts", false, "Also reset the activity attempts.") | ||
| s.Command.Flags().BoolVar(&s.ResetHeartbeats, "reset-heartbeats", false, "Reset the Activity's heartbeats. Only works with --reset-attempts.") | ||
| s.Command.Flags().BoolVar(&s.MatchAll, "match-all", false, "Every paused activity should be unpaused. This flag is ignored if activity-type is provided. Can only be used with --query.") | ||
| s.Jitter = 0 | ||
| s.Command.Flags().VarP(&s.Jitter, "jitter", "j", "The activity will start at random a time within the specified duration. Can only be used with --query.") | ||
| s.SingleWorkflowOrBatchOptions.buildFlags(cctx, s.Command.Flags()) | ||
| s.ActivityReferenceOptions.buildFlags(cctx, s.Command.Flags(), "unpause", true) | ||
| s.Command.Run = func(c *cobra.Command, args []string) { | ||
| if err := s.run(cctx, args); err != nil { | ||
| cctx.Options.Fail(err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.