two api-replicas with LB-nginx
This commit is contained in:
@@ -2,7 +2,7 @@ from collections.abc import AsyncIterator
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
from app.errors.exceptions import rate_limited
|
||||
from app.errors.exceptions import rate_limited, unavailable
|
||||
|
||||
|
||||
class RequestCapacity:
|
||||
@@ -29,6 +29,8 @@ def create_request_capacity(max_in_flight: int) -> RequestCapacity:
|
||||
|
||||
|
||||
async def acquire_request_slot(request: Request) -> AsyncIterator[None]:
|
||||
if request.app.state.lifecycle.draining:
|
||||
raise unavailable("Реплика завершает работу")
|
||||
capacity: RequestCapacity = request.app.state.request_capacity
|
||||
|
||||
if not capacity.try_acquire():
|
||||
|
||||
Reference in New Issue
Block a user