INNER CODE UNIT · Python
_sweep_stuck_investigations
KatrielMoses/voidaccess · api/main.py:228
async def _sweep_stuck_investigations(cutoff_minutes: Optional[int] = 30) -> int:
"""Mark investigations stuck in 'processing' as 'failed'.
Args:
cutoff_minutes: Only sweep rows older than this many minutes.
``None`` → startup mode: sweep *all* processing rows (the prior
process is gone, no legitimate owner remains).
``int`` → periodic mode: sweep only rows older than the cutoff.
Returns the number of rows swept. Returns 0 when DB is unconfigured,
the table is missing, or no rows match — never raises.
"""
if not os.getenv("DATABASE_URL"):
return 0
try:
from db.session import get_session
from db.models import Investigation