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 ¶
- type Outbox
- func (o *Outbox) Ack(epoch string, seq int64) error
- func (o *Outbox) Append(recs []hubproto.UsageRecord) (int64, error)
- func (o *Outbox) Asked() bool
- func (o *Outbox) Close() error
- func (o *Outbox) Epoch() string
- func (o *Outbox) Last() int64
- func (o *Outbox) Pending() int
- func (o *Outbox) PendingBytes() int64
- func (o *Outbox) Read(epoch string, after int64, limit int) (hubproto.UsageReadResult, error)
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 ¶
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 ¶
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 ¶
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) PendingBytes ¶
PendingBytes is how many bytes of the records file wait for an acknowledgement.