summaryrefslogtreecommitdiff
path: root/plugins/informer/rpc.go
blob: 8955af92c3e0aac3a66549801cb0d54d10af0807 (plain)
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
package informer

import (
	"github.com/spiral/roadrunner/v2/pkg/process"
)

type rpc struct {
	srv *Plugin
}

// WorkerList contains list of workers.
type WorkerList struct {
	// Workers is list of workers.
	Workers []process.State `json:"workers"`
}

// List all resettable services.
func (rpc *rpc) List(_ bool, list *[]string) error {
	*list = make([]string, 0, len(rpc.srv.registry))

	// append all plugin names to the output result
	for name := range rpc.srv.available {
		*list = append(*list, name)
	}
	return nil
}

// Workers state of a given service.
func (rpc *rpc) Workers(service string, list *WorkerList) error {
	workers, err := rpc.srv.Workers(service)
	if err != nil {
		return err
	}

	// write actual processes
	list.Workers = workers

	return nil
}