(ctx context.Context)
| 280 | } |
| 281 | |
| 282 | func (b *DBBatcher) run(ctx context.Context) { |
| 283 | //nolint:gocritic // System-level batch operation for connection logs. |
| 284 | authCtx := dbauthz.AsConnectionLogger(ctx) |
| 285 | for ctx.Err() == nil { |
| 286 | select { |
| 287 | case item := <-b.itemCh: |
| 288 | b.addToBatch(item) |
| 289 | |
| 290 | if b.batchLen() >= b.maxBatchSize { |
| 291 | b.flush(authCtx) |
| 292 | b.timer.Reset(b.interval, "connectionLogBatcher", "capacityFlush") |
| 293 | } |
| 294 | |
| 295 | case <-b.timer.C: |
| 296 | b.flush(authCtx) |
| 297 | b.timer.Reset(b.interval, "connectionLogBatcher", "scheduledFlush") |
| 298 | |
| 299 | case <-ctx.Done(): |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | b.log.Debug(ctx, "context done, flushing before exit") |
| 304 | |
| 305 | // Drain any remaining items from the channel. |
| 306 | for { |
| 307 | select { |
| 308 | case item := <-b.itemCh: |
| 309 | b.addToBatch(item) |
| 310 | default: |
| 311 | if b.batchLen() > 0 { |
| 312 | b.shutdownBatch(b.buildParams()) |
| 313 | } |
| 314 | // Signal the retry worker to skip delays and close |
| 315 | // the channel so it exits after processing any |
| 316 | // remaining items. |
| 317 | // Mark the batcher as closed so that any subsequent |
| 318 | // Upsert calls fail immediately instead of sending |
| 319 | // into itemCh after the run loop has exited. |
| 320 | close(b.retryCh) |
| 321 | return |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // batchEntry wraps a connection log event with explicit connect and |
| 327 | // disconnect times. When a connect and disconnect for the same session |
no test coverage detected