forked from mtusi2026/mtusi2026lab6
Проверить сквозной контекст, отказы, SLO и требования уровня 4
This commit is contained in:
+4
-1
@@ -51,7 +51,10 @@ def create_app() -> FastAPI:
|
||||
@app.middleware("http")
|
||||
async def add_request_id(request: Request, call_next):
|
||||
"""Добавляет идентификаторы запроса и процесса, ограничивает очередь."""
|
||||
request_id = request.headers.get("X-Request-Id", "") or str(uuid.uuid4())
|
||||
try:
|
||||
request_id = str(uuid.UUID(request.headers.get("X-Request-Id", "")))
|
||||
except ValueError:
|
||||
request_id = str(uuid.uuid4())
|
||||
request.state.request_id = request_id
|
||||
|
||||
# Ограничение числа обслуживаемых запросов в процессе.
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"clock_timestamp()-min(created_at)),0) AS age FROM attachment_jobs "
|
||||
"WHERE state IN ('queued','processing')").fetchone()
|
||||
windows = {}
|
||||
for window, seconds in [('30s',30),('1m',60),('2m',120),('5m',300)]:
|
||||
for window, seconds in [('15s',15),('30s',30),('1m',60),('2m',120),('5m',300)]:
|
||||
result = conn.execute("SELECT count(*) AS total, count(*) FILTER (WHERE "
|
||||
"state <> 'ready' OR updated_at-created_at > interval '5 seconds') AS bad "
|
||||
"FROM attachments WHERE created_at <= clock_timestamp()-interval '5 seconds' "
|
||||
|
||||
Reference in New Issue
Block a user