batching

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: AGPL-3.0, Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextBatchNumKey  = "batch_num"
	ContextBatchSizeKey = "batch_size"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchCb

type BatchCb func(ctx Context) error

type Batcher

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

func NewBatcher

func NewBatcher(cfg Config) (*Batcher, error)

NewBatcher creates a new Batcher with the given config.

func (*Batcher) Push

func (b *Batcher) Push(item Item) error

Push adds one item into the work queue.

func (*Batcher) Start

func (b *Batcher) Start()

Start begins the processing of batches at the configured interval. Should only be called once.

func (*Batcher) Stop

func (b *Batcher) Stop()

Stop stops the batching process. Should only be called once.

type Config

type Config struct {
	// The frequency at which batches should be executed.
	Interval time.Duration
	// The maximum size of the queue of items.
	Size int
	// An optional callback to be executed before processing a batch.
	// This is where expensive operations should usually be performed
	// in order to make the batching efficient.
	PreRunCb BatchCb
	// An optional callback to be executed after processing a batch.
	PostRunCb BatchCb
}

type Context

type Context map[string]any

type Item

type Item func(ctx Context)

Jump to

Keyboard shortcuts

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