queue

package
v0.0.11-beta.5 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeadLetterQueue

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

DeadLetterQueue provides disk-based resilience for failed database writes. When a batch insert fails, the data is serialized to JSON and written to disk. A background replay worker periodically attempts to re-insert failed batches with exponential backoff, bounded by configurable file count and disk limits.

func NewDLQ

func NewDLQ(dir string, interval time.Duration, replayFn func(data []byte) error) (*DeadLetterQueue, error)

NewDLQ creates a new Dead Letter Queue. maxFiles/maxDiskMB/maxRetries = 0 means unlimited.

func NewDLQWithLimits

func NewDLQWithLimits(dir string, interval time.Duration, replayFn func(data []byte) error,
	maxFiles int, maxDiskMB int64, maxRetries int) (*DeadLetterQueue, error)

NewDLQWithLimits creates a DLQ with explicit bounds.

func (*DeadLetterQueue) DiskBytes

func (d *DeadLetterQueue) DiskBytes() int64

DiskBytes returns the current total bytes of files in the DLQ directory.

func (*DeadLetterQueue) Enqueue

func (d *DeadLetterQueue) Enqueue(batch interface{}) error

Enqueue serializes the given batch to JSON and writes it to disk. Enforces file count and disk size limits (FIFO eviction when exceeded).

func (*DeadLetterQueue) SetMetrics

func (d *DeadLetterQueue) SetMetrics(onEnqueue, onSuccess, onFailure func(), onDiskBytes func(int64))

SetMetrics wires Prometheus metric callbacks into the DLQ.

func (*DeadLetterQueue) Size

func (d *DeadLetterQueue) Size() int

Size returns the number of files currently in the DLQ directory.

func (*DeadLetterQueue) Stop

func (d *DeadLetterQueue) Stop()

Stop gracefully shuts down the replay worker.

Jump to

Keyboard shortcuts

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