Keep print jobs in the SQLite job store
The job store now implements printqueue.Store on its one connection, so the queue can keep jobs on disk. A mutex serialises every call, since a transaction and the synchronous setting belong to the connection. - Add inserts the job, its deliveries and its content in one transaction. - Sending updates the delivery's row alone, at synchronous FULL, so the mark is on disk before the first byte goes to the printer. - Finish updates the delivery's row and drops exactly the jobs, deliveries and contents the queue names, in one transaction, synced when the queue asks, as it does for a failure. - Load turns every delivery in sending into uncertain and reads the jobs and deliveries, in one commit. It reads each content's length, not the content, and refuses a delivery whose job is gone or whose state this binary does not know; its errors name the file. - Job reads one job's content. - Idle runs a passive checkpoint while the queue has nothing to do, once 64 commits, about 20 jobs, have gathered since the last. The queue is idle after nearly every job when receipts come one at a time, and a checkpoint syncs the log and the database, and the next commit the log's header: checkpointing each time would turn a job's one sync into four. A synced commit sets synchronous FULL, commits, and returns to NORMAL even when the commit failed. Times are stored as Unix nanoseconds, so they read back to the nanosecond in UTC. Errors name the operation and the job's or delivery's sequence number, never a value. A test hook runs inside each commit and reads PRAGMA synchronous and total_changes(), so the tests see which commits are synced, the schema step included, and that Sending, and a Finish that drops nothing, change one row. With automatic checkpoints off, a job of 2 KB appended 8.6 WAL frames on the workstation; the test holds it to at most 16. Unique jobs' references are kept in the next commit. Nothing uses the store yet. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6e47cb713e
commit
f6323aa854
4 files changed
+815
-2
No files matched your search
@@ -57,6 +57,7 @@ modules from `go list`. The module path is the bare
|
||||
- server → modules, printqueue, receipt, printer, escpos
|
||||
- modules → receipt, ntfy
|
||||
- printqueue → receipt
|
||||
- jobstore → printqueue
|
||||
- receipt → escpos, raster
|
||||
- printer → escpos
|
||||
- internal/app → docs, server and the libraries
|
||||
@@ -64,6 +65,8 @@ modules from `go list`. The module path is the bare
|
||||
|
||||
Only `internal/app` reads config or wires in safehttp. Packages under
|
||||
`internal/pkg` take plain values, and escpos knows nothing of JSON or HTTP.
|
||||
printqueue defines its `Store` and imports no database; jobstore implements
|
||||
it on SQLite, so the server and tools/genopenapi never compile SQLite.
|
||||
|
||||
## Gate
|
||||
|
||||
|
||||
Reference in new issue
Block a user