d3c3025e64be98a36ec352d88ba186eadab9cdab
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d3c3025e64 |
Record a job done only once the printer confirms it
Breaking: a job reads done only once the printer has confirmed that it ran it, and holds the printer's connection until then. A job written in full that the printer does not confirm within printer.write_timeout now reads uncertain and is not sent again; before, it read done. Before each job, nothing is sent until the printer answers that it can print, so with its cover open or no paper a job is retried and fails, with no sent_at, as when the printer is unreachable, where before it read done. Receipts that take longer than write_timeout to print need a larger one. With confirmation the daemon also turns the printer's automatic status off (GS a 0) before each job and before its confirmation, so another client that relies on automatic status from the same printer stops getting it. printer.confirm = false keeps the old meaning of done and sends none of this. The third paper check of the job store showed why: with the TM-T88IV's cover open, Windows took all of a 128 KB receipt into its send buffer, so the job read done; the daemon stopped, and once the cover closed only the first third printed, without its cut. The printer was then left inside the image command, waiting for the rest, until it was switched off and on. The daemon now turns on the printer client's confirmation. The queue treats an unconfirmed send as written but unknown: it records the delivery uncertain, with an error that says the printer did not confirm it and that it may have printed in full, in part or not at all, logs it at WARN with the printer, and neither retries it nor reports it as a failure. Its commit is not synced: lost, it rolls back to sending, which the next start turns uncertain too. A printer that is not ready gives a plain error before the sending mark, which the queue retries as a failed dial. The new key printer.confirm, on by default, turns confirmation off for a printer that does not answer GS r with bits 4 and 7 clear, or does not answer DLE EOT on receipt; only the TM-T88IV is checked. The key's comments in config.go and the example config say what it sends and needs. docs/api.md warns that raw bytes which make the printer answer can be taken for the confirmation, and says that /healthz answers 503 timeout while a job holds the connection. It and design.md say that each job waits about 200 ms for answers still owed, for DLE EOT 1 to say that the printer is online, and for no answer to come late. design.md says why each connection opens with DLE EOT 1, GS a 0 and GS r 1, and names what stays open: a raw job holding a command answered with bits 4 and 7 clear, such as GS r, GS I, ESC v or ESC u 0, with printing after it, and an answer taken for the ready answer that is not it, one still queued when the fence arrived or one owed from before a late DLE EOT answer that stood in for the fence, followed by a pause of more than 100 ms while the printer reads online, as might happen during the TM-m50II's feed and cut at cover close. It relies on the printer answering DLE EOT on receipt and running GS a 0 in order, unverified beyond the TM-T88IV until stage 4a's raw-byte probe, and now says a send that fails part-way can print a whole receipt twice. The unit and install.md give the stop timeout with and without state.dir: without it the job being sent runs on from its rendering, image fetches included, up to the job's 2-minute cap, so such hosts keep systemd's default or set state.dir. configuration.md says the online check can add 2 s to write_timeout. The printers plan says what Send now does before a job, and its table of what a failed send can mean gains the ready wait and the confirmation. The tests' fake printers answer DLE EOT 1 and GS r 1 as an online printer with paper does; a test runs the daemon against one that answers that it is ready but never confirms the job. On paper, a receipt read done 884 ms after it was written, when the printer answered, and a receipt whose daemon was killed while it waited, with the cover open, read uncertain after the restart and printed once, cut short. With GS a 0 and DLE EOT 1, a receipt printed once with nothing extra and read done 888 ms after it was written; after a power cycle, with /healthz polled every 250 ms, one sent with the cover open waited 15.7 s with nothing sent and printed once, cut once, when the cover closed. With the fence, a receipt printed once with nothing extra and read done 921 ms after it was written. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
5cc4614ad7 |
Keep print jobs on disk in state.dir
Breaking: with state.dir set, jobs still waiting when the daemon stops or crashes print after the next start, in order and however old, instead of being marked failed or forgotten; a client that resends such jobs must stop. The Docker image sets state.dir, so a container keeps its jobs in /var/lib/uberbringer, and loses them with the container unless a volume is mounted there. The owner decided that jobs survive a restart and that a restart never prints a receipt twice. When state.dir is set, the daemon now opens the SQLite job store there, jobs.db, and the queue restores it before the subscriptions are made and before anything is served, so restored jobs go ahead of new ones and a second daemon on the directory stops before it reads the subscriptions' state. Without state.dir the queue keeps its jobs in memory, as before. The store closes once the queue has stopped. A job's sending mark is synced before its first byte, so one caught mid write reads uncertain after the restart and is never sent again; a job that had not reached the printer prints once. A store that cannot be opened stops the start with an error naming the file, rather than starting empty and forgetting which receipts are in doubt. The unit gains UMask=0077, so the store's files are its user's alone, and says why systemd's 90 s stop timeout is enough; the Dockerfile and docs/docker.md ask for --stop-timeout 40. design.md replaces "The queue lives in memory" with the store, the state machine, the sync policy, store failures, stage 1a's numbers, and that the ARM builds ship the store untested on ARM hardware. install.md and docker.md say how to set aside a store that will not open; configuration.md, api.md, cli.md and ntfy.md say what survives a restart. The license notices gain the driver's modules. TestServeRestart runs the daemon twice on one directory: jobs queued when the first run stops, its printer refusing connections, print in order after the restart, ahead of a new job, and a job seeded in sending between the runs reads uncertain and never reaches the printer. Part of stage 1d of docs/plans/job-store.md (decisions 14 and 15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
4eb620dde0 |
Check state.dir at start, with or without subscriptions
Breaking: the Docker image sets state.dir, so a container that cannot write /var/lib/uberbringer, one started --read-only without a volume there or with a bind mount owned by root, no longer starts, ntfy subscriptions or not: mount a named volume or a directory owned by 10001:10001. The daemon created state.dir and checked that it could write there only when an ntfy subscription was configured, since only subscriptions kept files in it. The job store will keep its database there too, so the check now runs once at start whenever state.dir is set: the directory is created 0700 if it is missing, and one that cannot be made or written stops the start with an error naming state.dir, before any subscription is made. A state.dir of only spaces is refused whether or not a subscription is configured, rather than made as a directory of that name. Without state.dir nothing changes. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
64a72903d8 |
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> |
||
|
|
8031135508 |
Keep finished jobs' content within queue.content_bytes
A job's content, its JSON, went from the store in the commit that finished it. The store is to keep it for longer, so that a finished job can be previewed or sent again by ID, but a count of jobs cannot bound that: at webserver.body_limit, 1000 finished jobs come to about 4 GB. The new key queue.content_bytes (default 64 MiB, 0 to 1 GiB) bounds the content of finished jobs instead, newest first. Statuses stay as queue.history says; a job past the budget keeps its status without its content. Unfinished jobs always keep their content, and so do uncertain ones while their status is kept, since a reprint needs it. What goes is dropped in the commit that finishes the job pushing it out. With the memory store the content is kept in memory, so the daemon may hold up to the budget more than before; at 1.5 KB per text job, the 1000 jobs of history take about 1.5 MB. Part of stage 1c of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
7e6cda16f8 |
Stop the print queue when its store fails
A store write that fails after start, such as on a full disk or a damaged page, must stop the daemon, and nothing is retried: a write that failed once seldom succeeds a moment later. The queue now stops on the first store error. Submit answers that error once and ErrClosed after, the job in hand writes nothing more to the store and keeps the state the store last recorded, so one not yet marked sending reads as queued again, and Run returns the error. A failure that an insert meets while shutdown waits for it is returned too. Every store error that stops the queue is marked ErrStoreFailed. serve logs it once at ERROR, reports it to Sentry once and stops the daemon. A request whose job could not be stored answers 500 internal_error without being logged or reported again, so the failure is reported once whoever submitted the job. docs/configuration.md lists it under Logs. With the memory store nothing fails, so the daemon behaves as before. Part of stage 1c of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
66531e7314 |
Replace ntfy.state_dir with a top-level [state] dir
The job store is to keep its database in the directory that holds the ntfy subscriptions' state files, so the directory moves to a section of its own: [state] dir, or UBERBRINGER_STATE_DIR, in place of [ntfy] state_dir. For now only the subscriptions use it. It still has no default and is still required with a subscription, and the checks at start name state.dir in their errors. install.sh writes [state] dir into new configs, and the Docker image sets UBERBRINGER_STATE_DIR. ntfy.state_dir has never been in a release, so its CHANGELOG entry changes in place and there is no fallback: a config that still sets it fails to load with an unknown key until the line moves to [state]. The image itself was not built, since the workstation has no Docker. Part of stage 1b of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3d451eb0b7 |
Split the README into focused docs under docs/
The README had grown to 658 lines. It is now a short overview: what Überbringer is, a quick start, a table of the docs and the licence. Each topic it held has a document of its own: - docs/install.md: install.sh, what it leaves behind, and upgrading. - docs/docker.md: the image behind a reverse proxy, the env file, health checks, and the ntfy state volume and token file. - docs/configuration.md: loading, environment variables, a table of every key in every section, and what is logged. The list of log messages becomes a summary of what is logged and reported. - docs/security.md: the API secret, issuing tokens and their scopes, the header-file recipe that keeps tokens off command lines (moved from docs/api.md), the reverse proxy, image URLs, and what is never logged. - docs/ntfy.md: the ntfy subscriptions, securing the topics and the printer's token, with the token scripts unchanged. - docs/cli.md: the command line. - docs/development.md: running from source, the Go version, make targets, the gate, generated files, the layout, CI and releases. CLAUDE.md names the new docs: a config key is now documented in docs/configuration.md, and the layout and Go version in docs/development.md. docs/api.md, design.md and the job-store plan point to the docs that now hold what they referred to in the README. The release archives also carry the docs on running the daemon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |