We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 82230b1 + 3121f02 commit 370f010Copy full SHA for 370f010
4 files changed
api/ps.go
@@ -10,11 +10,12 @@ type ProcessType map[string]string
10
11
// Pods defines the structure of a process.
12
type Pods struct {
13
- Release string `json:"release"`
14
- Type string `json:"type"`
15
- Name string `json:"name"`
16
- State string `json:"state"`
17
- Started time.Time `json:"started"`
+ Release string `json:"release,omitempty"`
+ Type string `json:"type,omitempty"`
+ Name string `json:"name,omitempty"`
+ State string `json:"state,omitempty"`
+ Started time.Time `json:"started,omitempty"`
18
+ Replicas int `json:"replicas,omitempty"`
19
}
20
21
// PodsList defines a collection of app pods.
@@ -28,11 +29,18 @@ func (p PodsList) Less(i, j int) bool { return p[i].Name < p[j].Name }
28
29
type PodType struct {
30
Type string
31
PodsList PodsList
32
+ Replicas int
33
+ Status string
34
35
36
// PodTypes holds groups of pods organized by type.
37
type PodTypes []PodType
38
39
+// Start is the definition of POST /v2/apps/<app_id>/stop or POST /v2/apps/<app_id>/start.
40
+type Types struct {
41
+ Types []string `json:"types,omitempty"`
42
+}
43
+
44
func (p PodTypes) Len() int { return len(p) }
45
func (p PodTypes) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
46
func (p PodTypes) Less(i, j int) bool { return p[i].Type < p[j].Type }
api/ps_test.go
@@ -9,10 +9,10 @@ import (
9
func TestPodsListSorted(t *testing.T) {
pods := PodsList{
- {"", "web", "web.fsdfgh4", "up", time.Time{}},
- {"", "web", "web.asdfgh1", "up", time.Time{}},
- {"", "web", "web.csdfgh3", "up", time.Time{}},
- {"", "web", "web.bsdfgh2", "up", time.Time{}},
+ {"", "web", "web.fsdfgh4", "up", time.Time{}, 4},
+ {"", "web", "web.asdfgh1", "up", time.Time{}, 4},
+ {"", "web", "web.csdfgh3", "up", time.Time{}, 4},
+ {"", "web", "web.bsdfgh2", "up", time.Time{}, 4},
sort.Sort(pods)
@@ -28,9 +28,9 @@ func TestPodsListSorted(t *testing.T) {
func TestPodTypesSorted(t *testing.T) {
podTypes := PodTypes{
- {"worker", PodsList{}},
- {"web", PodsList{}},
- {"clock", PodsList{}},
+ {"worker", PodsList{}, 4, "started"},
+ {"web", PodsList{}, 4, "started"},
+ {"clock", PodsList{}, 4, "started"},
sort.Sort(podTypes)
ps/ps.go
@@ -44,6 +44,40 @@ func Scale(c *drycc.Client, appID string, targets map[string]int) error {
return err
47
+// Stop decreases an app's processes to 0. The processes are specified in the target argument
48
+func Stop(c *drycc.Client, appID string, targets map[string][]string) error {
49
+ u := fmt.Sprintf("/v2/apps/%s/stop/", appID)
50
51
+ body, err := json.Marshal(targets)
52
53
+ if err != nil {
54
+ return err
55
+ }
56
57
+ res, err := c.Request("POST", u, body)
58
+ if err == nil {
59
+ return res.Body.Close()
60
61
62
63
64
+// Start increases an app's processes to setting. The processes are specified in the target argument
65
+func Start(c *drycc.Client, appID string, targets map[string][]string) error {
66
+ u := fmt.Sprintf("/v2/apps/%s/start/", appID)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Restart restarts an app's processes. To restart all app processes, pass empty strings for
82
// procType and name. To restart an specific process, pass an procType by leave name empty.
83
// To restart a specific instance, pass a procType and a name.
@@ -84,16 +118,26 @@ func ByType(processes api.PodsList) api.PodTypes {
84
118
for i, pt := range pts {
85
119
if pt.Type == process.Type {
86
120
exists = true
87
- pts[i].PodsList = append(pts[i].PodsList, process)
121
+ if process.Name != "" {
122
+ pts[i].PodsList = append(pts[i].PodsList, process)
123
88
124
break
89
125
90
126
91
127
92
128
// Is processtype for process doesn't exist, create a new one
93
129
if !exists {
130
+ p := api.PodsList{}
131
+ status := "stopped"
132
133
+ p = api.PodsList{process}
134
+ status = "started"
135
94
136
pts = append(pts, api.PodType{
95
137
Type: process.Type,
96
- PodsList: api.PodsList{process},
138
+ PodsList: p,
139
+ Replicas: process.Replicas,
140
+ Status: status,
97
141
})
98
142
99
143
0 commit comments