generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
healthcheck.go
51 lines (44 loc) · 1.25 KB
/
healthcheck.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
// Package healthcheck checks the health of the backend
package healthcheck
import (
"github.com/brevdev/brev-cli/pkg/cmdcontext"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/terminal"
"github.com/spf13/cobra"
)
type HealthcheckStore interface {
Healthcheck() error
}
func NewCmdHealthcheck(t *terminal.Terminal, store HealthcheckStore) *cobra.Command {
cmd := &cobra.Command{
Annotations: map[string]string{"housekeeping": ""},
Use: "healthcheck",
Short: "Check backend to see if it's healthy",
Long: "Check backend to see if it's healthy",
Example: `brev healthcheck`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := cmdcontext.InvokeParentPersistentPreRun(cmd, args)
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
err := healthcheck(t, store)
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
}
return cmd
}
func healthcheck(t *terminal.Terminal, store HealthcheckStore) error {
err := store.Healthcheck()
if err != nil {
t.Print("Not Healthy!")
return breverrors.WrapAndTrace(err)
}
t.Print("Healthy!")
return nil
}