MCPcopy Index your code
hub / github.com/coder/coder / retryBatch

Method retryBatch

enterprise/coderd/connectionlog/connectionlog.go:468–496  ·  view source on GitHub ↗

retryBatch retries writing a batch up to maxRetries times with a fixed delay between attempts. If the batcher context is canceled during a wait, one final attempt is made before returning.

(params database.BatchUpsertConnectionLogsParams)

Source from the content-addressed store, hash-verified

466// fixed delay between attempts. If the batcher context is canceled
467// during a wait, one final attempt is made before returning.
468func (b *DBBatcher) retryBatch(params database.BatchUpsertConnectionLogsParams) {
469 count := len(params.ID)
470 for attempt := range maxRetries {
471 t := b.clock.NewTimer(retryInterval, "connectionLogBatcher", "retryBackoff")
472 select {
473 case <-b.ctx.Done():
474 t.Stop()
475 b.shutdownBatch(params)
476 return
477 case <-t.C:
478 }
479
480 //nolint:gocritic // System-level batch operation for connection logs.
481 err := b.store.BatchUpsertConnectionLogs(dbauthz.AsConnectionLogger(b.ctx), params)
482 if err == nil {
483 return
484 }
485
486 b.log.Warn(b.ctx, "batch retry failed",
487 slog.Error(err),
488 slog.F("count", count),
489 slog.F("attempt", attempt+1),
490 slog.F("max_attempts", maxRetries),
491 )
492 }
493
494 b.log.Error(b.ctx, "batch retries exhausted, dropping batch",
495 slog.F("dropped", count))
496}
497
498// shutdownBatch makes a single write attempt during shutdown with a
499// bounded timeout so it can't hang indefinitely.

Callers 1

retryLoopMethod · 0.95

Calls 6

shutdownBatchMethod · 0.95
AsConnectionLoggerFunction · 0.92
StopMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected