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 3 commits
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
4 changes: 4 additions & 0 deletions internal/cmd/config/helptext/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,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 │ │ │ │ │
└──────────────────┴──────────────────────┴─────────────┴──────────────────┴─────────────────────────┴─────────────────┘
4 changes: 4 additions & 0 deletions internal/state/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ 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 wait, _ := config.OptionWait.Get(c.Config()); !wait {
return nil
}

quiet, err := config.OptionQuiet.Get(c.Config())
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions internal/state/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ var (
nil,
)

OptionWait = newOpt(
"wait",
"If false, do not wait for actions to complete",
true,
DefaultPreferenceFlags,
nil,
)

OptionDefaultSSHKeys = newOpt(
"default-ssh-keys",
"Default SSH keys for new servers",
Expand Down