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

Method run

enterprise/coderd/connectionlog/connectionlog.go:282–324  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

280}
281
282func (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

Callers 1

NewDBBatcherFunction · 0.95

Calls 9

addToBatchMethod · 0.95
batchLenMethod · 0.95
flushMethod · 0.95
shutdownBatchMethod · 0.95
buildParamsMethod · 0.95
AsConnectionLoggerFunction · 0.92
ErrMethod · 0.80
ResetMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected