Upsert enqueues a connection log entry for batched writing. It blocks if the internal buffer is full, ensuring no logs are dropped. It returns an error if the batcher or caller context is canceled.
(ctx context.Context, clog database.UpsertConnectionLogParams)
| 193 | // blocks if the internal buffer is full, ensuring no logs are dropped. |
| 194 | // It returns an error if the batcher or caller context is canceled. |
| 195 | func (b *DBBatcher) Upsert(ctx context.Context, clog database.UpsertConnectionLogParams) error { |
| 196 | if b.ctx.Err() != nil { |
| 197 | return b.ctx.Err() |
| 198 | } |
| 199 | |
| 200 | select { |
| 201 | case b.itemCh <- clog: |
| 202 | return nil |
| 203 | case <-b.ctx.Done(): |
| 204 | return b.ctx.Err() |
| 205 | case <-ctx.Done(): |
| 206 | return ctx.Err() |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Close cancels the batcher context, waits for the run loop and |
| 211 | // retry worker to exit. |