-
Notifications
You must be signed in to change notification settings - Fork 179
/
scale.go
91 lines (71 loc) · 1.68 KB
/
scale.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/convox/rack/cmd/convox/stdcli"
)
func init() {
stdcli.RegisterCommand(cli.Command{
Name: "scale",
Description: "scale an app's processes",
Usage: "PROCESS [--count 2] [--memory 512]",
Action: cmdScale,
Flags: []cli.Flag{
cli.StringFlag{
Name: "app",
Usage: "App name. Inferred from current directory if not specified.",
},
cli.StringFlag{
Name: "count",
Value: "",
Usage: "Number of processes to keep running for specified process type.",
},
cli.StringFlag{
Name: "memory",
Value: "",
Usage: "Amount of memory, in MB, available to specified process type.",
},
},
})
}
func cmdScale(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
if len(c.Args()) == 0 {
displayFormation(c, app)
return
}
process := c.Args()[0]
count := c.String("count")
memory := c.String("memory")
err = rackClient(c).SetFormation(app, process, count, memory)
if err != nil {
stdcli.Error(err)
return
}
displayFormation(c, app)
}
func displayFormation(c *cli.Context, app string) {
formation, err := rackClient(c).ListFormation(app)
if err != nil {
stdcli.Error(err)
return
}
pss, err := rackClient(c).GetProcesses(app, false)
if err != nil {
stdcli.Error(err)
return
}
running := map[string]int{}
for _, ps := range pss {
running[ps.Name] = running[ps.Name] + 1
}
t := stdcli.NewTable("NAME", "DESIRED", "RUNNING", "MEMORY")
for _, f := range formation {
t.AddRow(f.Name, fmt.Sprintf("%d", f.Count), fmt.Sprintf("%d", running[f.Name]), fmt.Sprintf("%d", f.Memory))
}
t.Print()
}