fix: chunk FIRMS bulk inserts under asyncpg 32767 bind cap

A ~90k-row INSERT ... ON CONFLICT dies with InterfaceError, so fire_loop
fails every poll and /api/health stays degraded (fires age > 30 min).
Chunk 2000 rows per statement, still one commit per poll.
This commit is contained in:
Sirius DevOps 2026-08-28 22:22:12 -04:00
commit 5302e261d7
2 changed files with 67 additions and 7 deletions

View file

@ -213,3 +213,55 @@ def test_ingest_fire_rows_one_execute_one_commit(monkeypatch):
assert inserted == 3
assert session.executes == 1
assert session.commits == 1
def test_fire_insert_chunk_stays_under_asyncpg_bind_limit():
"""asyncpg caps bind params at 32767 — a 93k-row INSERT dies."""
from ingestor import FIRE_INSERT_CHUNK, FIRE_ROW_BIND_PARAMS
assert FIRE_INSERT_CHUNK * FIRE_ROW_BIND_PARAMS < 32767
assert FIRE_INSERT_CHUNK >= 500
def test_ingest_fire_rows_chunks_when_over_limit(monkeypatch):
from ingestor import ingest_fire_rows
import ingestor
class _Session:
def __init__(self):
self.executes = 0
self.commits = 0
self.rowcount = 0
async def execute(self, *a, **k):
self.executes += 1
self.rowcount = 2 if self.executes < 3 else 1
return self
async def commit(self):
self.commits += 1
async def __aenter__(self):
return self
async def __aexit__(self, *a):
return False
session = _Session()
monkeypatch.setattr(ingestor, "async_session", lambda: session)
monkeypatch.setattr(ingestor, "FIRE_INSERT_CHUNK", 2)
async def no_corr(*a, **k):
return []
monkeypatch.setattr("fire_aircraft.correlate_and_notify", no_corr)
monkeypatch.setattr("geofence.record_and_notify", no_corr)
msgs = [
make_fire_msg(latitude=39.1 + i * 0.01, longitude=-121.1)
for i in range(5)
]
inserted = asyncio.run(ingest_fire_rows(msgs))
assert inserted == 5
assert session.executes == 3
assert session.commits == 1