DBBatcher holds a buffer of agent stats and periodically flushes them to its configured store.
| 31 | // DBBatcher holds a buffer of agent stats and periodically flushes them to |
| 32 | // its configured store. |
| 33 | type 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. |
| 57 | type BatcherOption func(b *DBBatcher) |
nothing calls this directly
no outgoing calls
no test coverage detected