Help us shape the future of Go! Take the 2026 Go Developer Survey

batcher

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package batcher provides batched event writing for Chronicle. Events are accumulated and flushed on size threshold, time interval, or shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

type Batcher struct {
	// contains filtered or unexported fields
}

Batcher accumulates events and flushes them in batches.

func New

func New(batchSize int, flushInterval time.Duration, flushFn FlushFunc, logger log.Logger) *Batcher

New creates a new Batcher.

func (*Batcher) Add

func (b *Batcher) Add(ctx context.Context, event *audit.Event) error

Add adds an event to the batch buffer. If the batch is full, it flushes immediately.

A failed flush leaves the events buffered so a later flush can retry, rather than dropping audit records because the store was briefly unavailable.

func (*Batcher) Flush

func (b *Batcher) Flush(ctx context.Context) error

Flush writes any buffered events. The buffer is only cleared once flushFn succeeds, so a failure can be retried without losing the batch.

func (*Batcher) Pending

func (b *Batcher) Pending() int

Pending reports how many events are buffered.

func (*Batcher) Start

func (b *Batcher) Start()

Start begins the background flush ticker.

func (*Batcher) Stop

func (b *Batcher) Stop(ctx context.Context) error

Stop signals the batcher to stop and flushes remaining events.

Safe to call more than once: a caller that both defers Stop and calls it on the shutdown path used to panic here, because stopCh was closed twice.

type FlushFunc

type FlushFunc func(ctx context.Context, events []*audit.Event) error

FlushFunc is called when a batch of events is ready to be persisted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL