diff options
author | Wolfy-J <[email protected]> | 2018-06-11 11:28:24 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-11 11:28:24 +0300 |
commit | 2f135b359575cc1625d1461bb6d8e478da8ccf54 (patch) | |
tree | 8561f84318c3a291f4a38df6b347954bda777e41 /service/http/rpc.go | |
parent | 6efaa0aa951240c2bb643761f103ee3f0fafb4d9 (diff) |
refactor
Diffstat (limited to 'service/http/rpc.go')
-rw-r--r-- | service/http/rpc.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/service/http/rpc.go b/service/http/rpc.go new file mode 100644 index 00000000..2adb8706 --- /dev/null +++ b/service/http/rpc.go @@ -0,0 +1,61 @@ +package http + +import ( + "github.com/pkg/errors" +) + +type rpcServer struct{ svc *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. + NumJobs int64 `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 { + if rpc.svc.srv == nil { + return errors.New("http server is not running") + } + + *r = "OK" + return rpc.svc.srv.rr.Reset() +} + +// Workers returns list of active workers and their stats. +func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { + if rpc.svc.srv == nil { + return errors.New("http server is not running") + } + + for _, w := range rpc.svc.rr.Workers() { + state := w.State() + r.Workers = append(r.Workers, Worker{ + Pid: *w.Pid, + Status: state.String(), + NumJobs: state.NumExecs(), + Created: w.Created.UnixNano(), + Updated: state.Updated().UnixNano(), + }) + } + + return nil +} |