spools

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	Create(handler FlushHandler) (Spool, error)
	Close() error
}

Factory creates and manages spool lifecycle.

func NewFileFactory

func NewFileFactory(fs afero.Fs, dir string, opts ...FileFactoryOption) (Factory, error)

NewFileFactory creates a file-backed spool factory.

type FailureStrategy

type FailureStrategy interface {
	OnExceededFailures(fs afero.Fs, inflightPath string) error
}

FailureStrategy defines the action to take when an inflight spool file exceeds the maximum number of consecutive flush failures.

func NewDeleteStrategy

func NewDeleteStrategy() FailureStrategy

NewDeleteStrategy creates a FailureStrategy that deletes inflight files when consecutive flush failures exceed the threshold.

func NewQuarantineStrategy

func NewQuarantineStrategy() FailureStrategy

NewQuarantineStrategy creates a FailureStrategy that quarantines inflight files by renaming them with a .quarantine suffix when consecutive flush failures exceed the threshold.

type FileFactoryOption

type FileFactoryOption func(*fileFactory)

FileFactoryOption configures a fileFactory.

func WithFailureStrategy

func WithFailureStrategy(s FailureStrategy) FileFactoryOption

WithFailureStrategy sets the strategy invoked when an inflight file exceeds the maximum number of consecutive flush failures. When nil (the default), inflight files are deleted on threshold breach.

func WithFlushBatchMaxBytes

func WithFlushBatchMaxBytes(bytes int64) FileFactoryOption

WithFlushBatchMaxBytes sets the maximum payload bytes returned per call to the next function passed to the Flush callback. Zero disables the limit.

func WithFlushBatchSize

func WithFlushBatchSize(n int) FileFactoryOption

WithFlushBatchSize sets the maximum number of frames returned per call to the next function passed to the Flush callback. Zero disables batching, causing all frames in the inflight file to be returned in a single batch.

func WithFlushInterval

func WithFlushInterval(interval time.Duration) FileFactoryOption

WithFlushInterval sets periodic flush interval. Zero disables the timer.

func WithFlushOnClose

func WithFlushOnClose(enabled bool) FileFactoryOption

WithFlushOnClose enables final flush during Close. Default is true.

func WithMaxActiveSize

func WithMaxActiveSize(bytes int64) FileFactoryOption

WithMaxActiveSize sets the maximum size (in bytes) for an active spool file. When an Append would cause the active file to exceed this limit, the current active file is rotated to a sealed inflight file and a fresh active file is started. Zero (default) means no size limit.

func WithMaxAppendsBeforeFlush

func WithMaxAppendsBeforeFlush(n int) FileFactoryOption

WithMaxAppendsBeforeFlush triggers flush after this many append calls. Zero disables this trigger.

func WithMaxBytesBeforeFlush

func WithMaxBytesBeforeFlush(bytes int64) FileFactoryOption

WithMaxBytesBeforeFlush triggers flush after this many appended bytes. Zero disables this trigger.

func WithMaxFailures

func WithMaxFailures(n int) FileFactoryOption

WithMaxFailures sets the per-key consecutive failure threshold before the failure strategy is invoked. Default is 20.

func WithNowFunc

func WithNowFunc(fn func() time.Time) FileFactoryOption

WithNowFunc overrides the clock used to generate inflight timestamps. Intended for testing.

type FlushHandler

type FlushHandler func(key string, next func() ([][]byte, error)) error

FlushHandler is called during flush cycles for each inflight file.

type Spool

type Spool interface {
	Append(key string, payload []byte) error
}

Spool is a crash-safe keyed append-only framed-file store.

Jump to

Keyboard shortcuts

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