-
Notifications
You must be signed in to change notification settings - Fork 40
/
combiner.go
57 lines (45 loc) · 1.1 KB
/
combiner.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
package probe
import (
"sync"
coreprober "github.com/bnb-chain/greenfield-storage-provider/core/prober"
)
type combined struct {
mu sync.Mutex
probes []coreprober.Prober
}
// Combine folds given probes into one, reflects their statuses in a thread-safe way.
func Combine(probes ...coreprober.Prober) coreprober.Prober {
return &combined{probes: probes}
}
// Ready sets components status to ready.
func (p *combined) Ready() {
p.mu.Lock()
defer p.mu.Unlock()
for _, probe := range p.probes {
probe.Ready()
}
}
// Unready sets components status to unready with given error as a cause.
func (p *combined) Unready(err error) {
p.mu.Lock()
defer p.mu.Unlock()
for _, probe := range p.probes {
probe.Unready(err)
}
}
// Healthy sets components status to healthy.
func (p *combined) Healthy() {
p.mu.Lock()
defer p.mu.Unlock()
for _, probe := range p.probes {
probe.Healthy()
}
}
// Unhealthy sets components status to unhealthy with given error as a cause.
func (p *combined) Unhealthy(err error) {
p.mu.Lock()
defer p.mu.Unlock()
for _, probe := range p.probes {
probe.Unhealthy(err)
}
}