-
Notifications
You must be signed in to change notification settings - Fork 11
/
service_info.go
65 lines (48 loc) · 1.15 KB
/
service_info.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package backend
import (
"context"
"code.vegaprotocol.io/vega/wallet/api/interactor"
)
type serviceInfo struct {
url string
cancelFunc context.CancelFunc
latestHealthState HealthCheckStatus
logFilePath string
responseChan chan interactor.Interaction
receptionChan chan interactor.Interaction
}
func newServiceInfo() *serviceInfo {
s := &serviceInfo{}
s.reset()
return s
}
func (s *serviceInfo) IsRunning() bool {
return s.cancelFunc != nil
}
func (s *serviceInfo) Health() HealthCheckStatus {
return s.latestHealthState
}
func (s *serviceInfo) SetHealth(state HealthCheckStatus) {
s.latestHealthState = state
}
func (s *serviceInfo) SetInfo(url string, logFilePath string) {
s.url = url
s.logFilePath = logFilePath
}
func (s *serviceInfo) OnShutdown(cancelFunc context.CancelFunc) {
s.cancelFunc = cancelFunc
}
func (s *serviceInfo) Shutdown() {
s.cancelFunc()
close(s.receptionChan)
close(s.responseChan)
s.reset()
}
func (s *serviceInfo) reset() {
s.url = ""
s.logFilePath = ""
s.latestHealthState = ""
s.cancelFunc = nil
s.receptionChan = make(chan interactor.Interaction, 1)
s.responseChan = make(chan interactor.Interaction, 1)
}