Add automatic instruction fetcher for official sets

Downloads official instruction PDFs from LEGO, located via the Brickset API, one set per interval (10 minutes by default) so neither API gets hammered. Official sets only; MOCs are excluded throughout.

- New admin page at /admin/instruction-fetch: queue builder, pacing controls, live countdown and per-set job history

- Database-backed queue (instruction_fetch_jobs) and last-run timestamp, so pacing survives restarts

- Background worker thread, plus 'flask instructions queue/run/status' for Task Scheduler or cron

- SHA-256 dedupe (instructions.sha256), PDF header check, size cap and streaming downloads via temp files

- brickset_api: getInstructions2 by set number and getInstructions by setID (the old code sent a set number to the setID method); getSets params now proper JSON; getKeyUsageStats added

- Schema top-ups applied automatically at boot: new table plus instructions.sha256/source

- Docker: fetcher env vars passed through compose, no worker thread in the entrypoint bootstrap
This commit is contained in:
jessikitty committed 2026-09-26 13:43:17 +10:00
1 parent aac2b60517
commit 89f65e2d74
23 files changed
+2073 -76

No files matched your search

+12
View File
@@ -26,3 +26,15 @@ BACKUP_KEEP=5
# Application Configuration
SETS_PER_PAGE=20
# --- Automatic instruction fetcher -----------------------------------------
# Pacing lives in the admin UI (Admin > Instruction Fetcher). These are the
# process-level knobs.
# Set to 0 to disable the background worker thread and drive the queue from
# Task Scheduler / cron with `flask instructions run` instead.
INSTRUCTION_FETCH_WORKER=1
# How often the worker checks whether the interval has elapsed, in seconds.
INSTRUCTION_FETCH_TICK_SECONDS=20
# Largest instruction PDF to accept, in megabytes.
FETCH_MAX_FILE_MB=150
FETCH_TIMEOUT_SECONDS=60