Documentation
¶
Overview ¶
Package notificationlog keeps the notifications that runs produced, so the Web inbox can show those that happened while no page was open.
The master directory holds one file per run, <masterdir>/notifications/ <run-id>.jsonl, with one record per notification batch. Only the run's own process appends to a file while it runs, so concurrent runs never write the same file, even on NFS; once it has stopped, rotari web may add one run.interrupted record through AppendOnce. Records are kept for Retention; inbox-state.json holds the shared read and cleared cursors of each basedir.
Index ¶
- Constants
- type Cursor
- type Cursors
- type Entry
- type InboxState
- type Log
- func (log Log) Advance(changes map[string]Cursors) (InboxState, error)
- func (log Log) Append(baseDir string, events []notification.Event) error
- func (log Log) AppendOnce(baseDir string, event notification.Event) (bool, error)
- func (log Log) Records() (records []Record, problems []string, err error)
- func (log Log) State() (InboxState, error)
- type Record
Constants ¶
const Retention = 10 * 24 * time.Hour
Retention is how long records are kept after their run's last record.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
Cursor is a position in the record order: by creation time, then ID.
type Cursors ¶
Cursors is one basedir's inbox state: its records up to Read are read, and its records up to Cleared are no longer shown.
type Entry ¶
type Entry struct {
Cursor
BaseDir string
Project string
RunID string
notification.BrowserMessage
}
Entry is one record as the Web inbox and `rotari notifications` show it.
type InboxState ¶
type InboxState struct {
// BaseDirs maps an absolute basedir to its cursors.
BaseDirs map[string]Cursors `json:"basedirs"`
}
InboxState is the inbox's shared state, kept per basedir so that reading or clearing the records of the basedirs a page shows leaves the others alone.
func (InboxState) For ¶
func (inbox InboxState) For(baseDir string) Cursors
For returns baseDir's cursors; a basedir never read has zero cursors.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is the record store under one master directory.
func Default ¶
Default returns the log under the resolved master directory; see state.ResolveMasterDir.
func (Log) Advance ¶
func (log Log) Advance(changes map[string]Cursors) (InboxState, error)
Advance moves the cursors of each basedir in changes forward; other basedirs keep theirs.
func (Log) Append ¶
func (log Log) Append(baseDir string, events []notification.Event) error
Append records events, all of one run under baseDir, as one record, then removes run files past Retention. The record is written with a single write, so a reader sees it whole or not at all.
func (Log) AppendOnce ¶
AppendOnce appends event, of one run under baseDir, unless the run's file already records an event of its kind. Callers of AppendOnce, in this and other processes, take turns, so the event is recorded once. It reports whether it appended.
type Record ¶
type Record struct {
SchemaVersion int `json:"schema_version"`
ID string `json:"id"`
CreatedAt string `json:"created_at"`
BaseDir string `json:"base_dir"`
Project string `json:"project"`
RunID string `json:"run_id"`
RunName string `json:"run_name,omitempty"`
Events []notification.Event `json:"events"`
}
Record is one notification batch of one run, with every event the run produced in it before any channel's selection.