Give each ntfy digest a reference of its own
Every digest went to the print queue under the fixed reference "digest", so after a crash the queue could not tell a digest it had queued from a new one. Once queued jobs survive a restart, a crash in the second between queueing a digest and saving the subscription's state would print it twice; the same window exists today for a digest that printed in that second. A digest now gets a reference of its own when it is made, "digest_" and a TypeID, and is saved with it in the subscription's state, apart from the held messages. It is offered to the queue only once that save has succeeded, and dropped once the queue takes it; while the state file cannot be written, digests wait. A restart with a saved digest offers that digest again first, with the same rows and reference, and the queue's duplicate check answers with the earlier job while it holds it. Messages held after a digest is made wait for the next one, also while quiet hours delay the saved digest after a restart: added to a digest the queue already holds, they would never print. The digest is submitted as unique, like a card. A digest can cost one more state save, two fsyncs. The reference shows in the log lines and Sentry reports where "digest" did. This completes stage 1c of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b8b7da0c6
commit
64a72903d8
12 files changed
+431
-58
No files matched your search
+18
-11
@@ -201,20 +201,22 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
match. A malformed scope can therefore never widen access.
|
||||
- **Jobs remember their source.** `Submit` takes a `Meta`: the source
|
||||
(`print`, `module:<name>` or `ntfy:<subscription>`) and a reference, the
|
||||
request ID on the HTTP routes and the message's ID, or `digest`, for a
|
||||
subscription. Job status shows the source and every
|
||||
request ID on the HTTP routes and the message's ID, or the digest's own
|
||||
reference, for a subscription. Job status shows the source and every
|
||||
worker log line of the job carries both, so a printed receipt can be
|
||||
traced to its request without logging what it says. The server copies
|
||||
both strings, since a request ID the client sent lives in a buffer that
|
||||
fasthttp reuses for the next request.
|
||||
A card's reference, its message's ID, is unique at its subscription: a
|
||||
card whose source and reference the queue holds, among the last 512 of
|
||||
that source kept apart from the statuses, is not queued again, and the
|
||||
queue answers with the earlier job. A message the subscription would
|
||||
hold for a digest never reaches Submit, so the subscription asks the
|
||||
queue first, and one whose card it holds counts as printed. So a
|
||||
message offered again after a restart prints once while its job is
|
||||
stored. A request ID is never checked, since a client may set it.
|
||||
A subscription's references are unique at it: a card's is its message's
|
||||
ID, and a digest's is a TypeID with the prefix `digest`, minted when the
|
||||
digest is made. A job whose source and reference the queue holds, among
|
||||
the last 512 of that source kept apart from the statuses, is not queued
|
||||
again, and the queue answers with the earlier job. A message the
|
||||
subscription would hold for a digest never reaches Submit, so the
|
||||
subscription asks the queue first, and one whose card it holds counts
|
||||
as printed. So a message or a digest offered again after a restart
|
||||
prints once while its job is stored. A request ID is never checked,
|
||||
since a client may set it.
|
||||
- **The preview reads the bytes back.** `escpos.Interpret` parses the stream
|
||||
the renderer produced, so the preview and the tests show what the printer
|
||||
receives rather than what the layout meant. It simulates the printer's own
|
||||
@@ -417,7 +419,12 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
during them, `quiet.min_priority` decides first. The receipt times are
|
||||
saved, so a restart cannot reset the budget. A digest lists 50
|
||||
messages and counts the rest; only those with a row count as printed
|
||||
for updates.
|
||||
for updates. Once made, a digest gets its reference and is saved with
|
||||
it, apart from the messages held, and is submitted only once that save
|
||||
has succeeded; messages held after that wait for the next digest. A
|
||||
restart before the queue's answer is saved submits the same digest
|
||||
again under the same reference, ahead of the later messages, so the
|
||||
queue's duplicate check finds it while its job is stored.
|
||||
- **Quiet hours print a morning digest (owner, 2026-11-30).** During a
|
||||
subscription's daily window only `quiet.min_priority` (5) and above
|
||||
print; the rest are held in the same digest buffer and print as one
|
||||
|
||||
Reference in new issue
Block a user