wrolpi/modules
Roland 9310fe801f
Make doc_modeler resilient to SQLite "database is locked"
A refresh on a large library aborted the whole doc_modeler run on the
first lock error, so the ~20k stranded docs never got modeled.

doc_modeler held one write transaction across a whole batch of 10 docs
while doing slow per-doc extraction (a PDF/epub can be tens of MB). When
another connection committed mid-batch, the deferred transaction failed
to upgrade to a write with SQLITE_BUSY_SNAPSHOT ("database is locked",
which busy_timeout does not absorb -- the same trap that motivated the
short-transaction rewrite of apply_indexers). The per-item error handler
then did `logger.error(f'... {file_group}')`, which lazy-loaded an
attribute on the now-rolled-back session and raised a *second* exception,
escaping the handler and aborting the entire modeler.

Restructure:
- Pick each batch of candidate ids in a short read-only transaction, then
  model each doc in its own short write transaction. A lock/error on one
  doc rolls back only that doc and cannot poison the rest of the run.
- Retry a doc a few times on "database is locked" -- a fresh transaction
  gets a fresh snapshot and succeeds.
- Log the plain file_group id on failure; never touch the ORM object on a
  possibly rolled-back session.
- Track only *failed* ids for the termination guard (successes are
  excluded by the Doc.id IS NULL gate), keeping the notin_ set small and
  well under SQLite's bound-variable limit.

Adds test_doc_modeler_survives_database_locked.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 13:44:27 -06:00
..
archive Remove stale Postgres references after SQLite cutover. 2026-07-18 13:28:54 -06:00
docs Make doc_modeler resilient to SQLite "database is locked" 2026-07-20 13:44:27 -06:00
flasher Flasher: chip-mismatch guard, WROLPi firmware table, colorblind chip colors 2026-07-02 17:26:37 -06:00
inventory Postgres -> SQLite hard cutover: the database moves into the media directory. 2026-07-12 14:09:37 -06:00
map Migrating map downloaders. 2026-05-07 15:54:53 -06:00
videos Remove stale Postgres references after SQLite cutover. 2026-07-18 13:28:54 -06:00
zim kiwix: a corrupt zim must not bring down the whole server 2026-07-20 13:06:46 -06:00
__init__.py Move One-Time Pad encryption to the browser (#479) 2026-06-13 13:52:34 -06:00