jtlevine Claude Opus 4.6 (1M context) commited on
Commit
9f98264
·
1 Parent(s): 5d9d818

Fast-fail DB writes: 5s timeout, disable after first failure

Browse files

Prevents broken Neon connections from blocking the entire pipeline
with thousands of timeout waits. After one failed write, DB is
disabled for the rest of the run and pipeline continues in-memory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. src/pipeline.py +5 -4
src/pipeline.py CHANGED
@@ -116,15 +116,16 @@ class HeatRiskPipeline:
116
  async def _db_write(self, fn, *args, **kwargs):
117
  """Call a database CRUD function. Silently skip if no db or on error.
118
 
119
- Usage: await self._db_write(insert_daily_reading, self.db, {...})
120
- The function is only called (and its coroutine created) when self.db is set.
121
  """
122
  if self.db is None:
123
  return None
124
  try:
125
- return await fn(*args, **kwargs)
126
  except Exception as exc:
127
- logger.warning("Database write failed (non-fatal): %s", exc)
 
128
  return None
129
 
130
  async def run(self) -> PipelineRunResult:
 
116
  async def _db_write(self, fn, *args, **kwargs):
117
  """Call a database CRUD function. Silently skip if no db or on error.
118
 
119
+ Disables DB writes after first failure to avoid blocking the pipeline
120
+ with repeated connection timeouts.
121
  """
122
  if self.db is None:
123
  return None
124
  try:
125
+ return await asyncio.wait_for(fn(*args, **kwargs), timeout=5.0)
126
  except Exception as exc:
127
+ logger.warning("Database write failed, disabling DB for this run: %s", exc)
128
+ self.db = None # Stop trying — don't block the pipeline
129
  return None
130
 
131
  async def run(self) -> PipelineRunResult: