-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomponent_status.go
More file actions
40 lines (32 loc) · 865 Bytes
/
component_status.go
File metadata and controls
40 lines (32 loc) · 865 Bytes
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
package process
import "time"
// HealthComponentStatus manages the current status of an application component.
type HealthComponentStatus struct {
health *Health
key interface{}
healthy bool
lastUpdated time.Time
}
func newHealthComponentStatus(health *Health, key interface{}) *HealthComponentStatus {
return &HealthComponentStatus{
health: health,
key: key,
}
}
// Healthy returns true if the component is currently healthy.
func (s *HealthComponentStatus) Healthy() bool {
s.health.mu.Lock()
defer s.health.mu.Unlock()
return s.healthy
}
// Update sets the current health status of the application component.
func (s *HealthComponentStatus) Update(healthy bool) {
s.health.mu.Lock()
defer s.health.mu.Unlock()
if s.healthy == healthy {
return
}
s.healthy = healthy
s.lastUpdated = time.Now()
s.health.notify()
}