spool

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spool is the durable local event buffer between agent hooks and the server.

Each event is one JSON file. Writers (short-lived hook processes, possibly many at once) create files in tmp/, fsync, and rename them into pending/. An uploader claims events by renaming pending/ → inflight/ (rename is atomic, so concurrent uploaders never claim the same file), deletes them after the server ACKs, and renames them back on failure. Files are only moved to dead/ when the server permanently rejects them; transient failures never drop events (at-least-once delivery).

File names are "<occurred_at unix nanos>_<event_id>.json" so a directory listing is in event order, and re-spooling the same event overwrites itself.

Index

Constants

This section is empty.

Variables

View Source
var ErrFull = errors.New("spool: capacity reached")

ErrFull is returned by Write when the spool is at capacity. The event is counted as dropped so the loss is visible in `memspace client status`.

Functions

This section is empty.

Types

type Limits

type Limits struct {
	MaxEvents int
	MaxBytes  int64
}

Limits bounds the spool size. Zero means unlimited.

type Record

type Record struct {
	EventID         string          `json:"event_id"`
	Agent           string          `json:"agent"`
	NativeSessionID string          `json:"native_session_id"`
	EventType       string          `json:"event_type"`
	OccurredAt      time.Time       `json:"occurred_at"`
	Project         project.Hint    `json:"project"`
	Payload         json.RawMessage `json:"payload"`
	Attempts        int             `json:"attempts,omitempty"`
	LastError       string          `json:"last_error,omitempty"`
	// contains filtered or unexported fields
}

Record is one spooled event plus the context needed to resolve it to server IDs at upload time.

type Spool

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

Spool manages the buffer rooted at a directory.

func Open

func Open(dir string, limits Limits) (*Spool, error)

Open creates the spool directories if needed.

func (*Spool) Ack

func (s *Spool) Ack(recs []*Record) error

Ack deletes events the server has durably accepted.

func (*Spool) Claim

func (s *Spool) Claim(max int) ([]*Record, error)

Claim moves up to max pending events to inflight/ and returns them in event order. Events another process claimed first are skipped.

func (*Spool) Dir

func (s *Spool) Dir() string

Dir returns the spool root.

func (*Spool) ListDead

func (s *Spool) ListDead() ([]*Record, error)

ListDead returns the dead letters (for inspection).

func (*Spool) PendingCount

func (s *Spool) PendingCount() int

PendingCount is a cheap check used to decide whether another upload round is needed.

func (*Spool) RecoverStale

func (s *Spool) RecoverStale(maxAge time.Duration) (int, error)

RecoverStale returns inflight events claimed longer than maxAge ago to pending/ — the uploader that claimed them crashed or was killed.

func (*Spool) Reject

func (s *Spool) Reject(recs []*Record, reason string) error

Reject moves events the server permanently refused to dead/.

func (*Spool) Release

func (s *Spool) Release(recs []*Record, reason string) error

Release returns claimed events to pending/ after a transient failure, recording the attempt. Nothing is ever dropped here.

func (*Spool) RequeueDead

func (s *Spool) RequeueDead() (int, error)

RequeueDead moves all dead letters back to pending/ for another attempt.

func (*Spool) Stats

func (s *Spool) Stats() (Stats, error)

Stats counts events in each state. It also refreshes the cached usage used by the capacity check.

func (*Spool) Write

func (s *Spool) Write(r Record) error

Write durably adds an event to pending/.

type Stats

type Stats struct {
	Pending, Inflight, Dead int
	PendingBytes            int64
	Dropped                 int64
	OldestPending           time.Time
}

Stats summarizes the spool for status output.

Jump to

Keyboard shortcuts

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