Skip to content
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

feat: allow not waiting for actions #843

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/cmd/config/helptext/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
│ endpoint │ Hetzner Cloud API │ string │ endpoint │ HCLOUD_ENDPOINT │ --endpoint │
│ │ endpoint │ │ │ │ │
├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤
│ no-wait │ If true, do not wait │ boolean │ no_wait │ HCLOUD_NO_WAIT │ --no-wait │
│ │ for actions to │ │ │ │ │
│ │ complete │ │ │ │ │
├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤
│ poll-interval │ Interval at which to │ duration │ poll_interval │ HCLOUD_POLL_INTERVAL │ --poll-interval │
│ │ poll information, │ │ │ │ │
│ │ for example action │ │ │ │ │
Expand All @@ -24,6 +20,10 @@
│ quiet │ If true, only print │ boolean │ quiet │ HCLOUD_QUIET │ --quiet │
│ │ error messages │ │ │ │ │
├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤
│ wait │ If false, do not │ boolean │ wait │ HCLOUD_WAIT │ --wait │
│ │ wait for actions to │ │ │ │ │
│ │ complete │ │ │ │ │
├──────────────────┼──────────────────────┼─────────────┼──────────────────┼─────────────────────────┼─────────────────┤
│ sort.<resource> │ Default sorting for │ string list │ sort.<resource> │ HCLOUD_SORT_<RESOURCE> │ │
│ │ resource │ │ │ │ │
└──────────────────┴──────────────────────┴─────────────┴──────────────────┴─────────────────────────┴─────────────────┘
2 changes: 1 addition & 1 deletion internal/state/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func (c *state) WaitForActions(cmd *cobra.Command, ctx context.Context, actions ...*hcloud.Action) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have "composite" commands in the CLI, where we wait for some actions and then make more API calls? These could fail if we do not wait for the initial actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for example when enabling protection after resource creation. How about we add a function like MustWaitForActions which doesn't include the wait option logic and then make WaitForActions a wrapper of that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine to me.

We should also look at these cases and decide if its really necessary to wait for the running actions or the next call is independent and can still be made. (ie. is it necessary for the server to start before enabling the protection?)

if noWait, _ := cmd.Flags().GetBool("no-wait"); noWait {
if wait, _ := config.OptionWait.Get(c.Config()); !wait {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions internal/state/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ var (
nil,
)

OptionNoWait = newOpt(
"no-wait",
"If true, do not wait for actions to complete",
false,
OptionWait = newOpt(
"wait",
"If false, do not wait for actions to complete",
true,
DefaultPreferenceFlags,
nil,
)
Expand Down