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

Struct DBBatcher

coderd/workspacestats/batcher.go:33–54  ·  view source on GitHub ↗

DBBatcher holds a buffer of agent stats and periodically flushes them to its configured store.

Source from the content-addressed store, hash-verified

31// DBBatcher holds a buffer of agent stats and periodically flushes them to
32// its configured store.
33type DBBatcher struct {
34 store database.Store
35 log slog.Logger
36
37 mu sync.Mutex
38 // TODO: make this a buffered chan instead?
39 buf *database.InsertWorkspaceAgentStatsParams
40 // NOTE: we batch this separately as it's a jsonb field and
41 // pq.Array + unnest doesn't play nicely with this.
42 connectionsByProto []map[string]int64
43 batchSize int
44
45 // tickCh is used to periodically flush the buffer.
46 tickCh <-chan time.Time
47 ticker *time.Ticker
48 interval time.Duration
49 // flushLever is used to signal the flusher to flush the buffer immediately.
50 flushLever chan struct{}
51 flushForced atomic.Bool
52 // flushed is used during testing to signal that a flush has completed.
53 flushed chan<- int
54}
55
56// Option is a functional option for configuring a Batcher.
57type BatcherOption func(b *DBBatcher)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected