loop runs the replica update sequence on an update interval.
(ctx context.Context)
| 151 | |
| 152 | // loop runs the replica update sequence on an update interval. |
| 153 | func (m *Manager) loop(ctx context.Context) { |
| 154 | defer m.closeWait.Done() |
| 155 | updateTicker := time.NewTicker(m.options.UpdateInterval) |
| 156 | defer updateTicker.Stop() |
| 157 | deleteTicker := time.NewTicker(m.options.CleanupInterval) |
| 158 | defer deleteTicker.Stop() |
| 159 | for { |
| 160 | select { |
| 161 | case <-ctx.Done(): |
| 162 | return |
| 163 | case <-deleteTicker.C: |
| 164 | // nolint:gocritic // Deleting a replica is a system function |
| 165 | err := m.db.DeleteReplicasUpdatedBefore(dbauthz.AsSystemRestricted(ctx), m.updateInterval()) |
| 166 | if err != nil { |
| 167 | m.logger.Warn(ctx, "delete old replicas", slog.Error(err)) |
| 168 | } |
| 169 | continue |
| 170 | case <-updateTicker.C: |
| 171 | } |
| 172 | err := m.syncReplicas(ctx) |
| 173 | if err != nil && !errors.Is(err, context.Canceled) { |
| 174 | m.logger.Warn(ctx, "run replica update loop", slog.Error(err)) |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // subscribe listens for new replica information! |
| 180 | func (m *Manager) subscribe(ctx context.Context) error { |
nothing calls this directly
no test coverage detected