diff --git a/api/__pycache__/dependency.cpython-313.pyc b/api/__pycache__/dependency.cpython-313.pyc index eb067d1..ef8b475 100644 Binary files a/api/__pycache__/dependency.cpython-313.pyc and b/api/__pycache__/dependency.cpython-313.pyc differ diff --git a/api/models/__pycache__/GenerationRequest.cpython-313.pyc b/api/models/__pycache__/GenerationRequest.cpython-313.pyc index 0726ddb..1bfa07a 100644 Binary files a/api/models/__pycache__/GenerationRequest.cpython-313.pyc and b/api/models/__pycache__/GenerationRequest.cpython-313.pyc differ diff --git a/api/service/__pycache__/generation_service.cpython-313.pyc b/api/service/__pycache__/generation_service.cpython-313.pyc index a0f1879..5e9d4e9 100644 Binary files a/api/service/__pycache__/generation_service.cpython-313.pyc and b/api/service/__pycache__/generation_service.cpython-313.pyc differ diff --git a/api/service/generation_service.py b/api/service/generation_service.py index d729d83..d426afa 100644 --- a/api/service/generation_service.py +++ b/api/service/generation_service.py @@ -22,6 +22,9 @@ from adapters.s3_adapter import S3Adapter logger = logging.getLogger(__name__) +# Limit concurrent generations to 4 +generation_semaphore = asyncio.Semaphore(4) + # --- Вспомогательная функция генерации --- async def generate_image_task( @@ -141,10 +144,12 @@ class GenerationService: generation_model.id = gen_id async def runner(gen): - logger.info(f"Starting background generation task for ID: {gen.id}") + logger.info(f"Generation {gen.id} entered queue (waiting for slot)...") try: - await self.create_generation(gen) - logger.info(f"Background generation task finished for ID: {gen.id}") + async with generation_semaphore: + logger.info(f"Starting background generation task for ID: {gen.id}") + await self.create_generation(gen) + logger.info(f"Background generation task finished for ID: {gen.id}") except Exception: # если генерация уже пошла и упала — пометим FAILED try: diff --git a/models/__pycache__/Generation.cpython-313.pyc b/models/__pycache__/Generation.cpython-313.pyc index cb9ecdb..d93d5e4 100644 Binary files a/models/__pycache__/Generation.cpython-313.pyc and b/models/__pycache__/Generation.cpython-313.pyc differ diff --git a/repos/__pycache__/dao.cpython-313.pyc b/repos/__pycache__/dao.cpython-313.pyc index 8427c18..a48a4f3 100644 Binary files a/repos/__pycache__/dao.cpython-313.pyc and b/repos/__pycache__/dao.cpython-313.pyc differ diff --git a/repos/__pycache__/generation_repo.cpython-313.pyc b/repos/__pycache__/generation_repo.cpython-313.pyc index a36ef06..34f973c 100644 Binary files a/repos/__pycache__/generation_repo.cpython-313.pyc and b/repos/__pycache__/generation_repo.cpython-313.pyc differ