Save a keepalive-only cursor move at most every 10 minutes
Each ntfy keepalive, every 45 seconds, moved the cursor and rewrote the subscription's state file with a synced write: about 1,900 a day per subscription while idle, which wears an SD card. A cursor that only keepalives or replayed repeats moved is now written at most every 10 minutes and at shutdown. A message printed, held or left out, a floor change, a digest, and the cursor's first move from 0 are still written within a second. A saved cursor that is behind costs only a longer replay after a crash, and the saved IDs drop what it sends again; a cursor still at 0 would mean a first start, which replays nothing. Tests check the lazy cadence and a crash that loses the later moves, the first move from 0 with an open event that has no time, and the write at shutdown. The soak now writes its state 325 times instead of 2,702. design.md records the decision. Its job-store entry now treats GORM on SQLite as the first choice and has the plan investigate SQLite in WAL mode, against bbolt and BadgerDB, before anything is built. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb0c021044
commit
ee65e72c44
6 files changed
+162
-24
No files matched your search
+21
-8
@@ -350,8 +350,15 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
daemon stops is lost, as any waiting job is: the queue stays in
|
||||
memory, because ESC/POS cannot say what printed.
|
||||
- State is one JSON file per subscription in `ntfy.state_dir`, written
|
||||
atomically (temporary file, fsync, rename) at most once a second and
|
||||
at shutdown, mode 0600 since held messages carry titles. A damaged
|
||||
atomically (temporary file, fsync, rename), mode 0600 since held
|
||||
messages carry titles. A change a restart must see, such as a message
|
||||
printed, held or left out, is written within a second, and so is the
|
||||
state at shutdown. A cursor that only keepalives moved is written at
|
||||
most every 10 minutes (owner, 2026-11-30): keepalives come every 45
|
||||
seconds, and writing each one would mean about 1,900 synced writes a
|
||||
day per subscription, which wears an SD card. A saved cursor that is
|
||||
behind costs only a longer replay after a crash, and the saved IDs
|
||||
drop the messages it sends again. A damaged
|
||||
file means a fresh start with a warning. `state_dir` has no default,
|
||||
since the daemon also runs on Windows; `install.sh` writes the unit's
|
||||
`StateDirectory`, `/var/lib/uberbringer`, and the image sets the same
|
||||
@@ -430,12 +437,18 @@ come from the config (owner, 2026-11-29).
|
||||
- **A persistent job store and print previews** (requested by the owner on
|
||||
2026-11-30; to be planned in full in `docs/plans/` before any of it is
|
||||
built):
|
||||
- Jobs stored with GORM on SQLite, so queued jobs, statuses and history
|
||||
survive a restart. Release builds use `CGO_ENABLED=0`, so the SQLite
|
||||
driver must be pure Go (for example `github.com/glebarez/sqlite`), and
|
||||
the database belongs in the unit's `StateDirectory`,
|
||||
`/var/lib/uberbringer`, the only directory it may write. The plan must
|
||||
also say how to tell which receipts printed
|
||||
- Jobs stored on disk, so queued jobs, statuses and history survive a
|
||||
restart. The owner's first choice is GORM on SQLite. Before anything
|
||||
is built, the plan investigates SQLite in WAL mode, through GORM or a
|
||||
lighter layer (owner, 2026-11-30): its disk writes per job, what each
|
||||
`synchronous` setting and checkpoint costs and guarantees, and whether
|
||||
it can record a job as printed durably at the moment its bytes are
|
||||
sent. The plan weighs it against key-value stores such as bbolt and
|
||||
BadgerDB on the same terms, and the choice is recorded here. Release
|
||||
builds use `CGO_ENABLED=0`, so any store must be pure Go (for SQLite,
|
||||
for example `github.com/glebarez/sqlite`), and its files belong in the
|
||||
unit's `StateDirectory`, `/var/lib/uberbringer`, the only directory it
|
||||
may write. The plan must also say how to tell which receipts printed
|
||||
before a crash, so a restart never prints a receipt twice.
|
||||
- A print preview as an image: a digital test print of a job that shows
|
||||
what the paper would look like, without printing. Formatters phase 1 adds
|
||||
|
||||
Reference in new issue
Block a user