startVerifyLoop runs in the background and periodically calls verify.
(ctx context.Context)
| 61 | |
| 62 | // startVerifyLoop runs in the background and periodically calls verify. |
| 63 | func (m *metricServer) startVerifyLoop(ctx context.Context) error { |
| 64 | go func() { |
| 65 | ticker := time.NewTicker(verifyLoopInterval) |
| 66 | defer ticker.Stop() |
| 67 | for ctx.Err() == nil { |
| 68 | select { |
| 69 | case <-ctx.Done(): |
| 70 | return |
| 71 | case <-m.shutdownCh: |
| 72 | log.Infof("Received interrupt signal, shutting down server.") |
| 73 | m.mu.Lock() |
| 74 | m.shutdownLocked(ctx) |
| 75 | m.mu.Unlock() |
| 76 | return |
| 77 | case <-ticker.C: |
| 78 | m.verify(ctx) |
| 79 | } |
| 80 | } |
| 81 | }() |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | // shutdownLocked shuts down the server. It assumes mu is held. |
| 86 | func (m *metricServer) shutdownLocked(ctx context.Context) { |