feat: Implement cancellation of stale generations in the service and repository, along with a new test.

This commit is contained in:
xds
2026-02-13 17:30:11 +03:00
parent 30138bab38
commit 279cb5c6f6
6 changed files with 109 additions and 6 deletions

View File

@@ -460,4 +460,15 @@ class GenerationService:
return True
except Exception as e:
logger.error(f"Error deleting generation {generation_id}: {e}")
return False
return False
async def cleanup_stale_generations(self):
"""
Cancels generations that have been running for more than 1 hour.
"""
try:
count = await self.dao.generations.cancel_stale_generations(timeout_minutes=60)
if count > 0:
logger.info(f"Cleaned up {count} stale generations (timeout)")
except Exception as e:
logger.error(f"Error cleaning up stale generations: {e}")