summaryrefslogtreecommitdiff
path: root/http/rpc.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-03 12:54:43 +0300
committerWolfy-J <[email protected]>2018-06-03 12:54:43 +0300
commit36ea77baa5a41de10bd604cd0e5b5b3cafaaeb64 (patch)
tree13ca8abd454a6668f490eec2e44b1520bd3953fe /http/rpc.go
parentb02611b7266589d888e054a1d2e4432ae370617d (diff)
service bus, http service, rpc bus, cli commands, new configs
Diffstat (limited to 'http/rpc.go')
-rw-r--r--http/rpc.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/http/rpc.go b/http/rpc.go
new file mode 100644
index 00000000..c096ff77
--- /dev/null
+++ b/http/rpc.go
@@ -0,0 +1,57 @@
+package http
+
+import (
+ "github.com/sirupsen/logrus"
+)
+
+type RPCServer struct {
+ Service *Service
+}
+
+// WorkerList contains list of workers.
+type WorkerList struct {
+ // Workers is list of workers.
+ Workers []Worker `json:"workers"`
+}
+
+// Worker provides information about specific worker.
+type Worker struct {
+ // Pid contains process id.
+ Pid int `json:"pid"`
+
+ // Status of the worker.
+ Status string `json:"status"`
+
+ // Number of worker executions.
+ NumExecs uint64 `json:"numExecs"`
+
+ // Created is unix nano timestamp of worker creation time.
+ Created int64 `json:"created"`
+
+ // Updated is unix nano timestamp of last worker execution.
+ Updated int64 `json:"updated"`
+}
+
+// Reset resets underlying RR worker pool and restarts all of it's workers.
+func (rpc *RPCServer) Reset(reset bool, r *string) error {
+ logrus.Info("resetting worker pool")
+ *r = "OK"
+
+ return rpc.Service.srv.rr.Reset()
+}
+
+// Workers returns list of active workers and their stats.
+func (rpc *RPCServer) Workers(list bool, r *WorkerList) error {
+ for _, w := range rpc.Service.srv.rr.Workers() {
+ state := w.State()
+ r.Workers = append(r.Workers, Worker{
+ Pid: *w.Pid,
+ Status: state.String(),
+ NumExecs: state.NumExecs(),
+ Created: w.Created.UnixNano(),
+ Updated: state.Updated().UnixNano(),
+ })
+ }
+
+ return nil
+}