Skip to content

Commit

Permalink
pause/resume show correct state, pause counts down
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Jun 24, 2020
1 parent 503e6b8 commit d97ea8f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cmd

import (
"fmt"
"github.com/superfly/flyctl/cmdctx"
"os"
"strconv"
"time"

"github.com/superfly/flyctl/cmdctx"

"github.com/AlecAivazis/survey/v2"
"github.com/logrusorgru/aurora"
Expand All @@ -15,6 +17,8 @@ import (
"github.com/superfly/flyctl/flyctl"
)

//TODO: Move all output to status styled begin/done updates

func newAppListCommand() *Command {

appsStrings := docstrings.Get("apps")
Expand Down Expand Up @@ -97,11 +101,25 @@ func runAppsList(ctx *cmdctx.CmdContext) error {
}

func runAppsPause(ctx *cmdctx.CmdContext) error {
app, err := ctx.Client.API().PauseApp(ctx.AppName)
_, err := ctx.Client.API().PauseApp(ctx.AppName)
if err != nil {
return err
}
fmt.Printf("%s is now %s\n", app.Name, app.Status)

appstatus, err := ctx.Client.API().GetAppStatus(ctx.AppName, false)

fmt.Printf("%s is now %s\n", appstatus.Name, appstatus.Status)

allocount := len(appstatus.Allocations)

for allocount > 0 {
fmt.Printf("Pausing %s with %d instance(s)\n", appstatus.Name, allocount)
time.Sleep(5 * time.Second)
appstatus, err = ctx.Client.API().GetAppStatus(ctx.AppName, false)
allocount = len(appstatus.Allocations)
}

fmt.Printf("%s is now %s with no instances running\n", appstatus.Name, appstatus.Status)
return nil
}

Expand All @@ -111,7 +129,10 @@ func runAppsResume(ctx *cmdctx.CmdContext) error {
return err
}

app, err = ctx.Client.API().GetApp(ctx.AppName)

fmt.Printf("%s is now %s\n", app.Name, app.Status)

return nil
}

Expand Down

0 comments on commit d97ea8f

Please sign in to comment.