-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpc.go
69 lines (52 loc) · 1.4 KB
/
rpc.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
package informer
import (
"github.com/roadrunner-server/api/v4/plugins/v4/jobs"
"github.com/roadrunner-server/pool/state/process"
)
type rpc struct {
plugin *Plugin
}
// WorkerList contains a list of workers.
type WorkerList struct {
// Workers are a list of workers.
Workers []*process.State `json:"workers"`
}
// List all plugins with workers.
func (rpc *rpc) List(_ bool, list *[]string) error {
*list = make([]string, 0, len(rpc.plugin.withWorkers))
// append all plugin names to the output result
for name := range rpc.plugin.withWorkers {
*list = append(*list, name)
}
return nil
}
// Workers state of a given service.
func (rpc *rpc) Workers(service string, list *WorkerList) error {
workers := rpc.plugin.Workers(service)
if workers == nil {
return nil
}
// write actual processes
list.Workers = workers
return nil
}
func (rpc *rpc) Jobs(plugin string, out *[]*jobs.State) error {
*out = rpc.plugin.Jobs(plugin)
return nil
}
func (rpc *rpc) AddWorker(plugin string, _ *bool) error {
return rpc.plugin.AddWorker(plugin)
}
func (rpc *rpc) RemoveWorker(plugin string, _ *bool) error {
return rpc.plugin.RemoveWorker(plugin)
}
// sort.Sort
func (w *WorkerList) Len() int {
return len(w.Workers)
}
func (w *WorkerList) Less(i, j int) bool {
return w.Workers[i].Pid < w.Workers[j].Pid
}
func (w *WorkerList) Swap(i, j int) {
w.Workers[i], w.Workers[j] = w.Workers[j], w.Workers[i]
}