MCPcopy
hub / github.com/grafana/dskit / AwaitHealthy

Method AwaitHealthy

services/manager.go:116–141  ·  view source on GitHub ↗

AwaitHealthy waits for the ServiceManager to become healthy. Returns nil, if manager is healthy, error otherwise (eg. manager is in a state in which it cannot get healthy anymore).

(ctx context.Context)

Source from the content-addressed store, hash-verified

114// AwaitHealthy waits for the ServiceManager to become healthy. Returns nil, if manager is healthy, error otherwise (eg. manager
115// is in a state in which it cannot get healthy anymore).
116func (m *Manager) AwaitHealthy(ctx context.Context) error {
117 select {
118 case <-ctx.Done():
119 return ctx.Err()
120 case <-m.healthyCh:
121 }
122
123 m.mu.Lock()
124 defer m.mu.Unlock()
125
126 if m.state != healthy {
127 terminated := len(m.byState[Terminated])
128
129 var failedReasons []string
130 for _, s := range m.byState[Failed] {
131 err := s.FailureCase()
132 if err != nil {
133 // err is never nil for a failed service.
134 failedReasons = append(failedReasons, err.Error())
135 }
136 }
137
138 return fmt.Errorf("not healthy, %d terminated, %d failed: %v", terminated, len(failedReasons), failedReasons)
139 }
140 return nil
141}
142
143// IsStopped returns true if all services are in terminal state (Terminated or Failed)
144func (m *Manager) IsStopped() bool {

Calls 5

ErrorfMethod · 0.80
DoneMethod · 0.65
FailureCaseMethod · 0.65
ErrMethod · 0.45
ErrorMethod · 0.45