Piotr Icikowski
d33e9f19ea
- refactored types, interfaces, options etc. - added new options dedicated for `StatefulProbe`s
40 lines
635 B
Go
40 lines
635 B
Go
package kubeprobes
|
|
|
|
import "sync"
|
|
|
|
type statusQuery struct {
|
|
allGreen bool
|
|
mux sync.Mutex
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
func (sq *statusQuery) isAllGreen() bool {
|
|
sq.wg.Wait()
|
|
sq.mux.Lock()
|
|
defer sq.mux.Unlock()
|
|
return sq.allGreen
|
|
}
|
|
|
|
func newStatusQuery(probes []ProbeFunction) *statusQuery {
|
|
sq := &statusQuery{
|
|
allGreen: true,
|
|
mux: sync.Mutex{},
|
|
wg: sync.WaitGroup{},
|
|
}
|
|
|
|
sq.wg.Add(len(probes))
|
|
for _, probe := range probes {
|
|
probe := probe
|
|
go func() {
|
|
defer sq.wg.Done()
|
|
if err := probe(); err != nil {
|
|
sq.mux.Lock()
|
|
sq.allGreen = false
|
|
sq.mux.Unlock()
|
|
}
|
|
}()
|
|
}
|
|
|
|
return sq
|
|
}
|