summaryrefslogtreecommitdiff
path: root/_____/utils/workers.go
blob: 1024b4c60eae09e97b0325807ff0715c58e53b12 (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
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
}