(ctx context.Context, key string, f func(any) bool)
| 231 | } |
| 232 | |
| 233 | func (c *Client) WatchKey(ctx context.Context, key string, f func(any) bool) { |
| 234 | watchBackoffConfig := c.backoffConfig |
| 235 | watchBackoffConfig.MaxRetries = 0 |
| 236 | bo := backoff.New(ctx, watchBackoffConfig) |
| 237 | syncTimer := time.NewTimer(c.pullerSyncTime) |
| 238 | defer syncTimer.Stop() |
| 239 | |
| 240 | for bo.Ongoing() { |
| 241 | out, _, err := c.kv.Query(ctx, dynamodbKey{ |
| 242 | primaryKey: key, |
| 243 | }, false) |
| 244 | if err != nil { |
| 245 | level.Error(c.logger).Log("msg", "error WatchKey", "key", key, "err", err) |
| 246 | |
| 247 | if bo.NumRetries() >= 10 { |
| 248 | level.Error(c.logger).Log("msg", "failed to WatchKey after retries", "key", key, "err", err) |
| 249 | if staleData := c.getStaleData(key); staleData != nil { |
| 250 | if !f(staleData) { |
| 251 | return |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | bo.Wait() |
| 256 | continue |
| 257 | } |
| 258 | |
| 259 | decoded, err := c.decodeMultikey(out) |
| 260 | if err != nil { |
| 261 | level.Error(c.logger).Log("msg", "error decoding key", "key", key, "err", err) |
| 262 | continue |
| 263 | } |
| 264 | c.updateStaleData(key, decoded, time.Now().UTC()) |
| 265 | |
| 266 | if !f(decoded) { |
| 267 | return |
| 268 | } |
| 269 | |
| 270 | bo.Reset() |
| 271 | utiltimer.ResetTimer(syncTimer, c.pullerSyncTime) |
| 272 | select { |
| 273 | case <-ctx.Done(): |
| 274 | return |
| 275 | case <-syncTimer.C: |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, any) bool) { |
| 281 | watchBackoffConfig := c.backoffConfig |
nothing calls this directly
no test coverage detected