-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
62 lines (49 loc) · 1.82 KB
/
process.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
package lade
import "fmt"
var _ ProcessService = new(ProcessClient)
type ProcessClient struct {
client *Client
}
type ProcessCreateOpts struct {
PlanID string `json:"plan_id"`
Command string `json:"command"`
}
type ProcessResizeOpts struct {
Height uint `json:"height"`
Width uint `json:"width"`
}
type ProcessUpdateOpts struct {
Processes []*Process `json:"processes"`
}
func (p *ProcessUpdateOpts) AddProcess(ptype, planID string, replicas int) {
process := &Process{Type: ptype, PlanID: planID, Replicas: replicas}
p.Processes = append(p.Processes, process)
}
type ProcessService interface {
Attach(appID string, number int, handler ConnHandler) error
Create(appID string, opts *ProcessCreateOpts) (*Process, error)
List(appID string) ([]*Process, error)
Resize(appID string, number int, opts *ProcessResizeOpts) error
Update(appID string, opts *ProcessUpdateOpts) ([]*Process, error)
}
func (p *ProcessClient) Attach(appID string, number int, handler ConnHandler) error {
path := fmt.Sprintf("apps/%s/processes/%d/attach", appID, number)
return p.client.doWebsocket(path, handler)
}
func (r *ProcessClient) Create(appID string, opts *ProcessCreateOpts) (process *Process, err error) {
process = new(Process)
err = r.client.doCreate("apps/"+appID+"/processes", opts, process)
return
}
func (p *ProcessClient) List(appID string) (processes []*Process, err error) {
err = p.client.doList("apps/"+appID+"/processes", nil, &processes)
return
}
func (p *ProcessClient) Resize(appID string, number int, opts *ProcessResizeOpts) error {
path := fmt.Sprintf("apps/%s/processes/%d/resize", appID, number)
return p.client.doUpdate(path, opts, nil)
}
func (p *ProcessClient) Update(appID string, opts *ProcessUpdateOpts) (processes []*Process, err error) {
err = p.client.doUpdate("apps/"+appID+"/processes", opts, &processes)
return
}