From 76ff8d1c95e087749d559ee5a4f8f0348feafffa Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Tue, 5 Jun 2018 16:23:14 +0300 Subject: Cs and refactoring --- cmd/_____/utils/workers.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cmd/_____/utils/workers.go (limited to 'cmd/_____/utils/workers.go') diff --git a/cmd/_____/utils/workers.go b/cmd/_____/utils/workers.go new file mode 100644 index 00000000..1024b4c6 --- /dev/null +++ b/cmd/_____/utils/workers.go @@ -0,0 +1,37 @@ +package utils + +import "github.com/spiral/roadrunner" + +// 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"` +} + +// FetchWorkers fetches list of workers from RR Server. +func FetchWorkers(srv *roadrunner.Server) (result []Worker) { + for _, w := range srv.Workers() { + state := w.State() + result = append(result, Worker{ + Pid: *w.Pid, + Status: state.String(), + NumExecs: state.NumExecs(), + Created: w.Created.UnixNano(), + Updated: state.Updated().UnixNano(), + }) + } + + return +} \ No newline at end of file -- cgit v1.2.3