Fast-fail DB writes: 5s timeout, disable after first failure
Browse filesPrevents 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>
- 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 |
-
|
| 120 |
-
|
| 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
|
|
|
|
| 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:
|