One producer scrapes at a time. The run takes a PostgreSQL session-level advisory lock
before the first chunk and releases it on exit; a second node logs the holder and exits
without work, because the corpus is idempotent and the holder ingests the same filings.
A missing driver or an unreachable database degrades to "unlocked" rather than stopping
the scrape.
Each run also upserts one row in scraper_heartbeat (run_id, phase, detail,
updated_at) at start, after metadata, before documents and at completion, so a hung
run is visible to the watchdog, not just an absent one.
Variable
Default
Meaning
SCRAPER_LOCK
1
Set to 0 for a manual run that must not wait for the lock.
SCRAPE_LOCK_KEY
917231002
Advisory-lock key. Change only if another tool needs the same key.
--coverage-report, --parity-report, and --verify are read-only reports that exit after printing.
A --limit also caps the number of documents Phase 2 processes.
Success — every configured sink's writes succeeded.
1
A configured sink failed a write, --verify found a difference between sinks, or configuration is invalid/unusable (unset/unknown DATABASE_TARGET, missing driver or connection details).
# Backfill documents only, 50 at a time
hkex-scraper--backfill-docs--limit50# Rebuild graph edges from existing filings
hkex-scraper--link-only
# Write to SQLite only for this run
hkex-scraper--database-targetpostgres--limit100# Validate config without writing
hkex-scraper--dry-run--limit10# Coverage and parity
hkex-scraper--coverage-report
hkex-scraper--database-targetpostgres,sqlite--parity-report
# Cross-sink reconciliation (filing ids + document hashes)
hkex-scraper--database-targetpostgres,sqlite--verify
# Version
hkex-scraper--version
Each run writes a timestamped log to logs/hkex_filings_<YYYY-MM-DD_HH-MM>.log in the working directory, and failed SurrealDB statements are appended to logs/hkex_failed.sql. Credentials are never written to either file.