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>
This commit is contained in:
1 parent
341353f702
commit
5cc4614ad7
20 files changed
+5144
-93
No files matched your search
+41
-2
@@ -174,13 +174,44 @@ Quiet hours are off unless the subscription has a
|
||||
|-----|---------|---------|
|
||||
| `size` | `100` | Jobs that may wait to print; more get `503` `queue_full` |
|
||||
| `history` | `1000` | Finished jobs whose status is kept; an older job's ID answers `404` `job_not_found` |
|
||||
| `content_bytes` | `67108864` | The bytes of finished jobs' content kept, newest first, each job as its JSON: 64 MiB, at most 1 GiB (`1073741824`). Jobs not yet finished keep theirs whatever the total, and so do `uncertain` jobs while their status is kept. The content is kept in memory |
|
||||
| `content_bytes` | `67108864` | The bytes of finished jobs' content kept, newest first, each job as its JSON: 64 MiB, at most 1 GiB (`1073741824`). Jobs not yet finished keep theirs whatever the total, and so do `uncertain` jobs while their status is kept. The content is kept in the [job store](#state) with `state.dir`, and in memory without it |
|
||||
|
||||
### state
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|-----|---------|---------|
|
||||
| `dir` | none | The directory the [ntfy subscriptions](#ntfy-subscriptions) keep their state in, one `ntfy-<name>.json` file each, readable by the daemon's user only. Required with a subscription, and never only spaces. When it is set, the daemon creates it, readable by its user only, if it is missing, and does not start if it cannot write there. `install.sh` and the Docker image set it to `/var/lib/uberbringer` |
|
||||
| `dir` | none | The directory of the job store, `jobs.db`, and of the [ntfy subscriptions](#ntfy-subscriptions)' state, one `ntfy-<name>.json` file each, all readable by the daemon's user only. Empty keeps jobs in memory. Required with a subscription, and never only spaces. When it is set, the daemon creates it, readable by its user only, if it is missing, and does not start if it cannot write there. `install.sh` and the Docker image set it to `/var/lib/uberbringer` |
|
||||
|
||||
With `state.dir`, the daemon keeps every job in the job store, `jobs.db`, a
|
||||
SQLite database, with its log `jobs.db-wal` beside it:
|
||||
|
||||
- Jobs still waiting when the daemon stops or crashes print after the next
|
||||
start, in order, however old, and every kept status answers after a
|
||||
restart. A job that was being sent to the printer when the daemon stopped
|
||||
reads `uncertain` and is never sent again
|
||||
([api.md](api.md#job-status)). Without `state.dir`, waiting jobs are
|
||||
marked failed when the daemon stops, and forgotten after a crash.
|
||||
- A job accepted from the HTTP routes is written to disk within about 30
|
||||
seconds, or sooner with the next job sent to the printer, so a power cut
|
||||
just after its `202` can lose it, but never prints it twice. A job from
|
||||
an ntfy subscription is on disk before it is queued.
|
||||
- One daemon uses a directory at a time: a second one on it does not
|
||||
start. No other program, the `sqlite3` command included, can read the
|
||||
database while the daemon runs.
|
||||
- The store holds what the receipts print, each job as its JSON, never a
|
||||
token. Its files are readable by the daemon's user only, and the content
|
||||
of a job that is gone can linger in the file's free pages until they are
|
||||
reused. `queue.content_bytes` bounds how much content is kept.
|
||||
- A store that cannot be opened, such as a damaged one, stops the daemon
|
||||
with an error naming the file. [install.md](install.md#a-job-store-that-will-not-open)
|
||||
and [docker.md](docker.md#a-job-store-that-will-not-open) say how to set
|
||||
it aside.
|
||||
- `jobs.db` and `jobs.db-wal` belong together: never delete the log, or
|
||||
copy the database without it.
|
||||
- Going back to 0.2.0: it refuses every key added since as unknown, such
|
||||
as `[state]`, `queue.content_bytes`, `printer.cut_feed` and the `ntfy`
|
||||
tables, so remove them first, and it never reads `jobs.db`, so the jobs
|
||||
waiting in it do not print.
|
||||
|
||||
### images
|
||||
|
||||
@@ -222,6 +253,14 @@ Request bodies and the `Authorization` header are never sent to Sentry.
|
||||
`module:<name>` or `ntfy:<name>`) and its `ref`, the ID of the request or
|
||||
ntfy message that sent it, or a digest's own reference, never with what
|
||||
it prints.
|
||||
- With `state.dir`, a start that finds jobs in the store logs
|
||||
`print queue restored` at INFO, with how many `jobs` it holds, how many
|
||||
are `waiting` and how many are `uncertain`. Each job that was being sent
|
||||
when the daemon stopped is logged at WARN once, by its `job_id`,
|
||||
`printer`, `source` and `ref`: it may have printed and is not sent again,
|
||||
so check the paper. A job that a stop catches before it reached the
|
||||
printer is logged at INFO as `job left queued` and prints after the
|
||||
start.
|
||||
- Each [ntfy subscription](ntfy.md) logs with its `subscription` name,
|
||||
never with what a message says or its topic. It logs at WARN when its
|
||||
connection is lost, when its credentials are refused and while the queue
|
||||
|
||||
Reference in new issue
Block a user