-
Notifications
You must be signed in to change notification settings - Fork 0
fix(serverless): bound async waits and wait on resume/activate #143
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
Open
Ryank90
wants to merge
1
commit into
rc/serverless
Choose a base branch
from
fix/serverless-wait-timeout
base: rc/serverless
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "fmt" | ||
| "log/slog" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| serverlessapi "github.com/runware/runware-cli/internal/api/serverless" | ||
|
|
@@ -107,15 +108,22 @@ func newAppsVersionsShowCmd(logger *log.Logger) *cobra.Command { | |
| } | ||
|
|
||
| func newAppsVersionsActivateCmd(logger *log.Logger) *cobra.Command { | ||
| return &cobra.Command{ | ||
| var ( | ||
| wait bool | ||
| timeout time.Duration | ||
| pollInterval time.Duration | ||
| ) | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "activate <appId> <versionNumber>", | ||
| Short: "Activate a ready application version", | ||
| Long: `Activate a ready version by number, including rollback to an older version. | ||
|
|
||
| The server accepts the deploy and returns immediately with the updated app. | ||
| Worker rollout is asynchronous; this command does not wait until workers are | ||
| healthy. Re-activating the currently active version is permitted and re-applies | ||
| it. On a stopped app the version is recorded and applied on resume. | ||
| Worker rollout is asynchronous. Pass --wait to poll until the application is | ||
| active or failed, and --timeout to bound that wait. Re-activating the currently | ||
| active version is permitted and re-applies it. On a stopped app the version is | ||
| recorded and applied on resume. | ||
|
|
||
| A missing app is 404. A missing version, a version that is not ready, or an | ||
| app that is deleting is 409.`, | ||
|
|
@@ -124,7 +132,10 @@ app that is deleting is 409.`, | |
| runware serverless apps versions activate my-app 2 | ||
|
|
||
| # roll back to an older ready version | ||
| runware serverless apps versions activate my-app 1`, | ||
| runware serverless apps versions activate my-app 1 | ||
|
|
||
| # wait until the rollout is active or failed | ||
| runware serverless apps versions activate my-app 2 --wait --timeout 5m`, | ||
| Args: cobra.ExactArgs(2), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| appID := args[0] | ||
|
|
@@ -142,11 +153,28 @@ app that is deleting is 409.`, | |
| spin.Stop() | ||
| return err | ||
| } | ||
| if wait && !serverlessapi.AppDeployTerminal(app.Status) { | ||
| _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Application %s is %s; waiting...\n", app.AppId, app.Status) | ||
| spin.SetMessage(fmt.Sprintf("Waiting for application %s...", app.AppId)) | ||
| app, err = waitForApp(cmd.Context(), client, app.AppId, pollInterval, timeout) | ||
| if err != nil { | ||
| spin.Stop() | ||
| return err | ||
| } | ||
| } | ||
| spin.Stop() | ||
|
|
||
| return output.Print(cmdutil.FormatFor(cmd), appResult(*app)) | ||
| if err := output.Print(cmdutil.FormatFor(cmd), appResult(*app)); err != nil { | ||
| return err | ||
| } | ||
| if !wait { | ||
| return nil | ||
| } | ||
| return appFailedErr(cmd.Context(), client, app) | ||
|
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. risk: activate on a stopped app answers |
||
| }, | ||
| } | ||
| addAppWaitFlags(cmd, &wait, &timeout, &pollInterval) | ||
| return cmd | ||
| } | ||
|
|
||
| func newAppsVersionsDeleteCmd(logger *log.Logger) *cobra.Command { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug: activate on a live app answers
active(SetActiveVersion keepsactive; the roll never leavesactiveand restores the old pin if it fails).AppDeployTerminal(active)is true, so--waitnever polls and exits 0 before workers roll. A failed rollback looks like success. The API has no rollout-progress field (events are free text), so--waitcannot follow this case. Skip the wait onactiveand print that the roll runs in the background, and fix the help text. Or drop--waitfrom activate until the API exposes rollout state.