notificationlog

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT 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 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

View Source
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

type Cursor struct {
	CreatedAt string `json:"created_at"`
	ID        string `json:"id"`
}

Cursor is a position in the record order: by creation time, then ID.

func (Cursor) After

func (cursor Cursor) After(other Cursor) bool

After reports whether cursor comes after other. The zero cursor comes before every record.

func (Cursor) Valid

func (cursor Cursor) Valid() bool

Valid reports whether cursor is the zero cursor or a record position.

type Cursors

type Cursors struct {
	Read    Cursor `json:"read"`
	Cleared Cursor `json:"cleared"`
}

Cursors is one basedir's inbox state: its records up to Read are read, and its records up to Cleared are no longer shown.

func (Cursors) Valid

func (cursors Cursors) Valid() bool

Valid reports whether both cursors are valid.

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.

func Entries

func Entries(records []Record, limit int) []Entry

Entries renders records, in their order, with each project's current browser settings, up to limit entries (no limit when limit is 0). A record whose events the settings all leave out gives no entry; a project whose settings cannot be read gives an entry that says so.

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

func Default() (Log, error)

Default returns the log under the resolved master directory; see state.ResolveMasterDir.

func Open

func Open(masterDir string) Log

Open returns the log under masterDir.

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

func (log Log) AppendOnce(baseDir string, event notification.Event) (bool, error)

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.

func (Log) Records

func (log Log) Records() (records []Record, problems []string, err error)

Records returns the kept records, newest first. A record that cannot be read is left out and described in problems; an incomplete last line, a record still being written, is not a problem.

func (Log) State

func (log Log) State() (InboxState, error)

State returns the shared inbox state.

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.

func (Record) Cursor

func (record Record) Cursor() Cursor

Cursor returns the record's position.

Jump to

Keyboard shortcuts

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