billingspool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package billingspool owns the process-local durable terminal handoff.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPendingCapacity      = errors.New("billingspool: pending record capacity exhausted")
	ErrPayloadCapacity      = errors.New("billingspool: pending payload capacity exhausted")
	ErrDatabaseCapacity     = errors.New("billingspool: database capacity exhausted")
	ErrFreeDiskCapacity     = errors.New("billingspool: free disk capacity exhausted")
	ErrFingerprintConflict  = errors.New("billingspool: stable key fingerprint conflict")
	ErrSpoolClosed          = errors.New("billingspool: spool is closed")
	ErrWorkerAlreadyRunning = errors.New("billingspool: flusher already running")
)

Functions

func ValidateStablePath

func ValidateStablePath(path string) error

ValidateStablePath rejects volatile OS temp directories for durable spool state.

Types

type Config

type Config struct {
	Path                   string
	DB                     *bun.DB
	MaxPendingRecords      int
	MaxPendingPayloadBytes int64
	MaxDatabaseBytes       int64
	MinFreeDiskBytes       int64
	ProcessedRetention     time.Duration
	ClaimTimeout           time.Duration
	BackoffBase            time.Duration
	BackoffMax             time.Duration
	Now                    func() time.Time
	// CommitAcknowledgedHook is test-only fault injection. It runs after the
	// SQLite commit and before Append returns, making the acknowledgement edge
	// observable without weakening the commit-before-success contract.
	CommitAcknowledgedHook func() error
	// FreeDiskBytes is an injectable filesystem watermark probe. Production
	// callers may provide the platform-specific durable-state probe; nil means
	// the database-size and pending-payload bounds remain authoritative.
	FreeDiskBytes func() int64
}

type Health

type Health struct {
	PendingRecords         int
	PendingPayloadBytes    int64
	DatabaseBytes          int64
	LiveDatabaseBytes      int64
	FreeDiskBytes          int64
	OldestPendingAge       time.Duration
	ErrorRows              int
	AppendCapacityFailures uint64
	LastDeliveryError      string
	ProbeError             string
	State                  HealthState
}

type HealthState

type HealthState string
const (
	HealthReady    HealthState = "ready"
	HealthDegraded HealthState = "degraded"
	HealthFull     HealthState = "full"
)

type Spool

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

func New

func New(ctx context.Context, cfg Config, sink billing.TerminalUsageSink) (*Spool, error)

func Open

func Open(ctx context.Context, cfg Config, sink billing.TerminalUsageSink) (*Spool, error)

func (*Spool) AppendCall

func (s *Spool) AppendCall(ctx context.Context, r billing.CallUsageRecord) error

func (*Spool) AppendLeg

func (s *Spool) AppendLeg(ctx context.Context, r billing.CallLegUsageRecord) error

func (*Spool) Close

func (s *Spool) Close() error

func (*Spool) Health

func (s *Spool) Health() Health

func (*Spool) PendingCount

func (s *Spool) PendingCount() int

func (*Spool) ProcessOnce

func (s *Spool) ProcessOnce(ctx context.Context) error

func (*Spool) Start

func (s *Spool) Start(ctx context.Context) error

func (*Spool) Stop

func (s *Spool) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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