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 ¶
- Variables
- type Limits
- type Record
- type Spool
- func (s *Spool) Ack(recs []*Record) error
- func (s *Spool) Claim(max int) ([]*Record, error)
- func (s *Spool) Dir() string
- func (s *Spool) ListDead() ([]*Record, error)
- func (s *Spool) PendingCount() int
- func (s *Spool) RecoverStale(maxAge time.Duration) (int, error)
- func (s *Spool) Reject(recs []*Record, reason string) error
- func (s *Spool) Release(recs []*Record, reason string) error
- func (s *Spool) RequeueDead() (int, error)
- func (s *Spool) Stats() (Stats, error)
- func (s *Spool) Write(r Record) error
- type Stats
Constants ¶
This section is empty.
Variables ¶
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 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 (*Spool) Claim ¶
Claim moves up to max pending events to inflight/ and returns them in event order. Events another process claimed first are skipped.
func (*Spool) PendingCount ¶
PendingCount is a cheap check used to decide whether another upload round is needed.
func (*Spool) RecoverStale ¶
RecoverStale returns inflight events claimed longer than maxAge ago to pending/ — the uploader that claimed them crashed or was killed.
func (*Spool) Release ¶
Release returns claimed events to pending/ after a transient failure, recording the attempt. Nothing is ever dropped here.
func (*Spool) RequeueDead ¶
RequeueDead moves all dead letters back to pending/ for another attempt.