Model/tests/applications
Jun-te Kim 17b9ae08eb Hold one DB connection per modelling_e2e invocation
The modelling_e2e Lambda held up to ~4 concurrent Postgres connections per
invocation: the read Session stayed open across the write loop (the catalogue
was queried live and overrides were read per-Property), each per-Property Unit
of Work opened a second, and the TaskOrchestrator ran on its own NullPool
engine — so the pool needed pool_size=2 + max_overflow=1 just for the modelling
work. Under 32 concurrent containers that approached RDS max_connections.

Restructure the handler to read everything up front — overrides, Scenario, an
in-memory catalogue snapshot, and stored Solar — through one short-lived read
Session, close it, then write each Property in a sequential Unit of Work. The
read and write Sessions no longer overlap, so the engine drops to pool_size=1,
max_overflow=0. Fold the orchestrator onto the same pooled engine: its repos
commit on every save, releasing the connection between bookkeeping calls, so it
holds none during the work. One invocation now uses one connection at a time.

The catalogue becomes a per-invocation snapshot (MaterialSnapshotRepository),
mirroring ProductPostgresRepository.get exactly — same drift mapping, lowest-id
pick, and errors — but priced after the Session closes. Transaction isolation
is preserved: per-Property writes and orchestrator bookkeeping keep their own
independent transactions, just drawn sequentially from a single connection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 16:58:21 +00:00
..
ara_first_run refactor(ara): rename FirstRunPipeline → AraFirstRunPipeline (PR #1139 review) 2026-06-01 15:00:33 +00:00
audit_generator put db engine construction inside handler to avoid import errors in test 2026-06-09 15:18:42 +00:00
landlord_description_overrides Classify the landlord Hot Water and Heating columns into categories 🟥 2026-06-19 14:07:14 +00:00
magic_plan define MagicPlanConfig class to get environment variables 2026-06-05 15:46:32 +00:00
modelling_e2e Hold one DB connection per modelling_e2e invocation 2026-06-24 16:58:21 +00:00
__init__.py feat(ara): AraFirstRunTriggerBody + ara_first_run lambda skeleton (#1130) 2026-05-30 20:38:15 +00:00