Documentation
¶
Overview ¶
Package histlog is the history log: one JSON line appended for each change sitrep makes to its state, and none for a read. It is a record beside the files, which stay the source of truth, and nothing replays it. See docs/HISTORY-LOG.md.
Index ¶
Constants ¶
const ( QueueAdd = "queue.add" QueueRm = "queue.rm" QueueEdit = "queue.edit" QueueMove = "queue.move" QueueReorder = "queue.reorder" Pin = "pin" Unpin = "unpin" Snooze = "snooze" Unsnooze = "unsnooze" Alias = "alias" Prune = "prune" SessionStart = "session.start" SessionEnd = "session.end" Restore = "restore" // one entry for a whole restore: counts, and no item text )
The operations a log records.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶ added in v1.0.7
Canonical reads the bytes of a log file that came from somewhere else, and writes them again the way this package writes a log: a line that is not valid JSON, that is too long, that has an operation or a host or an id this package does not know, or that repeats the id of an entry already kept, is dropped, and the text fields are cleaned and cut. What remains is made only from fields that this package has parsed, so nothing else of the original gets through. It says how many lines it kept and how many it dropped; an empty line is neither.
func CanonicalAll ¶ added in v1.0.7
CanonicalAll is Canonical for several files that make one log (the previous and the current), in the order given: an entry id that one file has kept is dropped from the next, as the reader reads the two files as one.
func Host ¶
Host makes a name for a machine that is safe to store and show: letters, digits, underscore and hyphen, at most 64 of them.
Types ¶
type Entry ¶
type Entry struct {
Op string
ID state.ID // the session, or the inbox
Text textsafe.Text // the item, the Objective or the name
Old textsafe.Text // queue.edit: the text before; alias: the name before
From int // queue.reorder: the position the item left
To int // queue.reorder: the position it took
Dest state.ID // queue.move: the queue it went to, with ID as the queue it left
}
Entry is one change. It describes the outcome, not the command: items are named by their text, and a position is a fact about the moment.
type Item ¶
type Item struct {
E string
Time time.Time
Host string
ID state.ID
Op string
Text textsafe.Text
Old textsafe.Text
From int
To int
Dest state.ID
}
Item is an entry as a reader sees it. Every text in it has been made safe again, because the file is untrusted.
type Log ¶
type Log struct {
Dir string // the state folder
Host string // the name of this host, as Host makes it
On bool
MaxMB int // the size limit for both files together
Days int // the age limit
Now func() time.Time
}
Log writes entries to one host's files. The zero Log is off and writes nothing.
func (Log) Check ¶ added in v1.0.7
Check says whether the log folder can be used: it is made when it is not there, and a link or a file where it belongs is an error.
func (Log) Clear ¶
Clear removes the log files, each by its own path, and then the folder if that is now empty.
func (Log) Record ¶
Record appends an entry. It is called after the change succeeded, and it never fails: on any error the entry is dropped (invariant 4).
func (Log) Replace ¶ added in v1.0.7
Replace makes the two log files of this folder what the arguments are, under the log's lock: each is written to a temporary file in the log folder first, and only then are the two renamed, one after the other, so that a failure while writing leaves the log as it was. A nil argument removes that file. The caller has made the bytes with Canonical. An entry that another process appends while this runs may be lost, since appends do not take the lock.
type Query ¶
type Query struct {
Host string // only this host; empty means every host in the folder
ID state.ID // only this queue or session (as a source or a destination); empty means all
Op string // only this operation
Since time.Time
Days int // entries older than this many days are ignored, whatever Since says
Now time.Time
Limit int // the most recent this many, or all when below 1
}
Query chooses what Read returns.