Answer a repeated ntfy message with its earlier job

Once queued jobs survive a restart, a crash in the second between
queueing an ntfy message and saving the subscription's state would
print the message twice: the replay offers it again. A card is now
submitted as unique by its message's ID. If the queue already holds
that source and reference, Submit queues nothing and returns the
earlier job, or its ID and source once its status is gone, and logs
the repeat. The queue keeps the last 512 references of each source
apart from the statuses, so queue.history = 0 cannot defeat the check,
and they come back on restore.

A replayed message that quiet hours or the paper budget would hold for
a digest never reaches Submit, so the check could not answer it, and
it would print again as a digest row. Before it holds a message, the
subscription now asks the queue through its handler whether it holds
that message's card; if so, the message counts as printed and is not
held.

Only unique jobs take part. On the HTTP routes the reference is a
request ID, which a client may set, so a check on it could answer a
new request with an old job. A unique insert is stored with a sync,
since the subscription treats the message as dealt with once it is
queued.

Part of stage 1c of docs/plans/job-store.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 13:50:09 -06:00
1 parent 792ee26af5
commit 8b8b7da0c6
8 files changed
+336 -17

No files matched your search

+8
View File
@@ -207,6 +207,14 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
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.
- **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