-
Notifications
You must be signed in to change notification settings - Fork 221
/
monitor.go
54 lines (42 loc) · 1.35 KB
/
monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package monitor
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/watch"
)
// New initializes and returns a new monitor Command.
func New() (cmd *cobra.Command) {
const (
short = `Monitor currently running application deployments`
long = short + `. Use Control-C to stop output.`
)
cmd = command.New("monitor", short, long, run,
command.RequireSession,
command.RequireAppName)
cmd.Args = cobra.NoArgs
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
)
return
}
func run(ctx context.Context) (err error) {
appName := appconfig.NameFromContext(ctx)
client := client.FromContext(ctx).API()
app, err := client.GetAppMonitoring(ctx, appName)
if err != nil {
return fmt.Errorf("failed to get app from context")
}
if app.CurrentRelease == nil {
return fmt.Errorf("app %s has not been deployed yet", appName)
}
if !app.CurrentRelease.InProgress {
return fmt.Errorf("app %s is not currently deploying a release. The build and release command must succeed before a release is deployed. The latest release version is %d", appName, app.CurrentRelease.Version)
}
return watch.Deployment(ctx, appName, app.CurrentRelease.EvaluationID)
}