forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.go
71 lines (59 loc) · 1.59 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
package main
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
"github.com/flynn/flynn/controller/client"
ct "github.com/flynn/flynn/controller/types"
)
func init() {
register("scale", runScale, `
usage: flynn scale [-r <release>] <type>=<qty>...
Scale changes the number of jobs for each process type in a release.
Options:
-r, --release <release> id of release to scale (defaults to current app release)
Example:
$ flynn scale web=2 worker=5
`)
}
// takes args of the form "web=1", "worker=3", etc
func runScale(args *docopt.Args, client *controller.Client) error {
scaleRelease := args.String["--release"]
if scaleRelease == "" {
release, err := client.GetAppRelease(mustApp())
if err == controller.ErrNotFound {
return errors.New("No app release, specify a release with -release")
}
if err != nil {
return err
}
scaleRelease = release.ID
}
formation, err := client.GetFormation(mustApp(), scaleRelease)
if err == controller.ErrNotFound {
formation = &ct.Formation{
AppID: mustApp(),
ReleaseID: scaleRelease,
Processes: make(map[string]int),
}
} else if err != nil {
return err
}
if formation.Processes == nil {
formation.Processes = make(map[string]int)
}
for _, arg := range args.All["<type>=<qty>"].([]string) {
i := strings.IndexRune(arg, '=')
if i < 0 {
fmt.Println(commands["scale"].usage)
}
val, err := strconv.Atoi(arg[i+1:])
if err != nil {
fmt.Println(commands["scale"].usage)
}
formation.Processes[arg[:i]] = val
}
return client.PutFormation(formation)
}