usageoutbox

package
v0.16.355 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 12 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 usageoutbox is the machine's outbox of spend facts (docs/hub/usage.md): records with a monotonic seq within an epoch, kept on disk until the hub says it has stored them. The hub pulls them (usage.read) and acknowledges (usage.ack); nothing here knows what a record means, and none of them carries the text of a conversation.

The folder holds two files. records.jsonl is one JSON record per line, in seq order, appended and synced; meta.json holds the epoch, the last acknowledged seq and whether the hub has ever read. A folder that is gone is a new epoch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Outbox

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

Outbox is safe for concurrent use.

func Open

func Open(dir string, now func() time.Time) (*Outbox, error)

Open makes the outbox in dir, or opens the one that is there. A missing or unreadable meta file makes a new epoch and drops whatever records were there: they belong to an epoch the hub may no longer know. now is the clock (nil is the real one).

func (*Outbox) Ack

func (o *Outbox) Ack(epoch string, seq int64) error

Ack answers usage.ack: records up to seq of this epoch are dropped. Another epoch's ack, or one for a seq already acknowledged, changes nothing; a seq beyond the newest record counts as the newest.

func (*Outbox) Append

func (o *Outbox) Append(recs []hubproto.UsageRecord) (int64, error)

Append gives the records their seqs and the machine's time, writes them in one synced write and returns the seq of the last. The records passed in are not changed.

func (*Outbox) Asked

func (o *Outbox) Asked() bool

Asked says whether the hub has read this epoch. It is kept on disk, so a restarted machine knows the hub is interested without waiting for a read.

func (*Outbox) Close

func (o *Outbox) Close() error

Close closes the file.

func (*Outbox) Epoch

func (o *Outbox) Epoch() string

Epoch is the id of the epoch this outbox is in.

func (*Outbox) Last

func (o *Outbox) Last() int64

Last is the seq of the newest record written (0 when none ever was).

func (*Outbox) Pending

func (o *Outbox) Pending() int

Pending is how many records wait for an acknowledgement.

func (*Outbox) PendingBytes

func (o *Outbox) PendingBytes() int64

PendingBytes is how many bytes of the records file wait for an acknowledgement.

func (*Outbox) Read

func (o *Outbox) Read(epoch string, after int64, limit int) (hubproto.UsageReadResult, error)

Read answers usage.read. The records are those with seq > after of the asked epoch, at most limit (clamped to 1..hubproto.UsageReadMax); a different epoch is read from its beginning. The same epoch and after give the same records until they are acknowledged.

Jump to

Keyboard shortcuts

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