summaryrefslogtreecommitdiff
path: root/plugins/informer/rpc.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-18 11:24:20 +0300
committerValery Piashchynski <[email protected]>2020-11-18 11:24:20 +0300
commit2b395a5f1bd431a2a9c80c35a2ca5f42066c9ffd (patch)
tree1542b018ee2aa8511f5e8a8b64b2f45c52e91048 /plugins/informer/rpc.go
parenta2ba8de5eb519f73044a9b1c66f087a5b65e3d45 (diff)
parent0a48a027642a34c560717526c55f70b7260d678c (diff)
Merge branch 'release_2.0' into plugin/http
Diffstat (limited to 'plugins/informer/rpc.go')
-rw-r--r--plugins/informer/rpc.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/informer/rpc.go b/plugins/informer/rpc.go
new file mode 100644
index 00000000..de47a739
--- /dev/null
+++ b/plugins/informer/rpc.go
@@ -0,0 +1,53 @@
+package informer
+
+import (
+ "github.com/spiral/roadrunner/v2"
+ "github.com/spiral/roadrunner/v2/interfaces/log"
+)
+
+type rpc struct {
+ srv *Plugin
+ log log.Logger
+}
+
+// WorkerList contains list of workers.
+type WorkerList struct {
+ // Workers is list of workers.
+ Workers []roadrunner.ProcessState `json:"workers"`
+}
+
+// List all resettable services.
+func (rpc *rpc) List(_ bool, list *[]string) error {
+ rpc.log.Info("Started List method")
+ *list = make([]string, 0, len(rpc.srv.registry))
+
+ for name := range rpc.srv.registry {
+ *list = append(*list, name)
+ }
+ rpc.log.Debug("list of services", "list", *list)
+
+ rpc.log.Info("successfully finished List method")
+ return nil
+}
+
+// Workers state of a given service.
+func (rpc *rpc) Workers(service string, list *WorkerList) error {
+ rpc.log.Info("started Workers method", "service", service)
+ workers, err := rpc.srv.Workers(service)
+ if err != nil {
+ return err
+ }
+
+ list.Workers = make([]roadrunner.ProcessState, 0)
+ for _, w := range workers {
+ ps, err := roadrunner.WorkerProcessState(w)
+ if err != nil {
+ continue
+ }
+
+ list.Workers = append(list.Workers, ps)
+ }
+ rpc.log.Debug("list of workers", "workers", list.Workers)
+ rpc.log.Info("successfully finished Workers method")
+ return nil
+}