-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_check.go
45 lines (36 loc) · 1.06 KB
/
health_check.go
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
38
39
40
41
42
43
44
45
package uwe
import (
"encoding/json"
"github.com/sheb-gregor/sam"
)
const (
// StatusAction is a command useful for health-checks, because it returns status of all workers.
StatusAction = "status"
// PingAction is a simple command that returns the "pong" message.
PingAction = "ping"
)
// AppInfo is a details of the *Application* build.
type AppInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Build string `json:"build"`
Tag string `json:"tag"`
}
// SocketName returns name of *Chief Service Socket*.
func (app AppInfo) SocketName() string {
return "/tmp/_uwe_" + app.Name + ".socket"
}
// StateInfo is result the `StatusAction` command.
type StateInfo struct {
App AppInfo `json:"app"`
Workers map[WorkerName]sam.State `json:"workers"`
}
// ParseStateInfo decodes `StateInfo` from the JSON response for the `StatusAction` command.
func ParseStateInfo(data json.RawMessage) (*StateInfo, error) {
var res = new(StateInfo)
err := json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}