Documentation
¶
Overview ¶
Package state persists bentoo-tray's state: the feed ETag and serial, the read state and source of every notice, the pause end, the backoff and the earliest next fetch.
Index ¶
Constants ¶
const Format = 2
Format is the state file version this package writes.
Variables ¶
var ErrCorrupt = errors.New("state file is damaged")
ErrCorrupt marks a state file that could not be parsed or carries an unknown format. Load has already moved it aside and returned a fresh state; the caller only has to WARN. Any other Load error is a real read failure.
Functions ¶
This section is empty.
Types ¶
type Record ¶
type Record struct {
Title string `json:"title"`
Summary string `json:"summary"`
URL string `json:"url"`
Severity string `json:"severity"`
Type string `json:"type"`
Source string `json:"source"`
Read bool `json:"read"`
Notified bool `json:"notified"`
LastSeen time.Time `json:"last_seen"`
Updated time.Time `json:"updated"`
}
Record is what is kept per notice. Summary lets a held or failed notification be rebuilt after a 304 or a restart. Source is "feed", "news", or "" for a record migrated from format 1, whose source is unknown.
type State ¶
type State struct {
Format int `json:"format"`
ETag string `json:"etag"`
Serial int64 `json:"serial"`
Notices map[string]Record `json:"notices"`
PauseUntil time.Time `json:"pause_until"`
Failures int `json:"failures"`
// NextFetch is the earliest time the next fetch may run; zero means none is
// scheduled.
NextFetch time.Time `json:"next_fetch"`
// Established reports that the first run is over: a check has accepted
// a feed, or read the news when no feed is configured. A state without it
// is a first run even once saved, so a first run can persist its backoff
// and Retry-After without ending. A format 1 file loads
// established: it was only ever written after the first run.
Established bool `json:"established"`
// Saved reports that a file was loaded or written; it is derived, never
// stored.
Saved bool `json:"-"`
}
State is everything bentoo-tray remembers between runs.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes one state file.
func (*Store) Load ¶
Load reads the state. A missing file is a first run: a fresh state with Saved and Established false. A format 1 file is loaded with every record's Source left "", Established set (a format 1 tray wrote no state before its first run was over) and Format set to 2 in memory, so the next Save writes format 2. A format 2 file without "established" is a first run. A file that cannot be parsed or carries a format other than 1 or 2 is moved to <path>.corrupt-<unix time> and a fresh state is returned together with an error wrapping ErrCorrupt.