init commit: create skeleton from lab1

This commit is contained in:
2026-10-16 22:39:23 +03:00
parent 65003b6119
commit aecd8d2957
70 changed files with 3205 additions and 8 deletions
+22
View File
@@ -0,0 +1,22 @@
from collections.abc import Generator
from threading import BoundedSemaphore
from fastapi import Request
from app.errors.exceptions import rate_limited
def create_request_capacity(max_in_flight: int) -> BoundedSemaphore:
return BoundedSemaphore(max_in_flight)
def acquire_request_slot(request: Request) -> Generator[None, None, None]:
semaphore: BoundedSemaphore = request.app.state.request_capacity
if not semaphore.acquire(blocking=False):
raise rate_limited()
try:
yield
finally:
semaphore.release()