Проверить уровень 3, устойчивость и отрицательные сценарии, оформить отчёт
This commit is contained in:
+2
-1
@@ -16,6 +16,7 @@ from src.models import ErrorResponse
|
||||
from src.routes import chats, health, messages, users, attachments
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
from src.storage import storage
|
||||
from src.identity import INSTANCE_ID
|
||||
|
||||
|
||||
from src import telemetry
|
||||
@@ -32,7 +33,7 @@ def create_app() -> FastAPI:
|
||||
finally:
|
||||
await run_in_threadpool(storage.pool.close)
|
||||
|
||||
instance_id = uuid.uuid4().hex
|
||||
instance_id = INSTANCE_ID
|
||||
app = FastAPI(title="MTUSI Messenger Lab7", version="1.7.0", lifespan=lifespan)
|
||||
|
||||
@app.exception_handler(BotoCoreError)
|
||||
|
||||
+2
-2
@@ -1,12 +1,13 @@
|
||||
"""Bound the actual ASGI stream, including requests without Content-Length."""
|
||||
import json
|
||||
import uuid
|
||||
from src.identity import INSTANCE_ID
|
||||
|
||||
|
||||
class BodyLimit:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.instance = uuid.uuid4().hex.encode()
|
||||
self.instance = INSTANCE_ID.encode()
|
||||
|
||||
async def __call__(self, scope, receive, send):
|
||||
if scope['type'] != 'http':
|
||||
@@ -20,7 +21,6 @@ class BodyLimit:
|
||||
size += len(message.get('body', b''))
|
||||
if size > maximum:
|
||||
request_id = str(uuid.uuid4())
|
||||
import socket
|
||||
body = json.dumps({'error': {'code':'payload_too_large', 'message':'размер запроса превышен',
|
||||
'request_id':request_id}}).encode()
|
||||
await send({'type':'http.response.start', 'status':413, 'headers':[
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
"""One public random process alias, without container hostname or address."""
|
||||
import uuid
|
||||
|
||||
INSTANCE_ID = uuid.uuid4().hex
|
||||
-60
@@ -176,63 +176,3 @@ def recover_expired():
|
||||
and not owns(conn, job, job)):
|
||||
settle_error(conn, job, 'lease_expired')
|
||||
|
||||
|
||||
def replay(attachment_id):
|
||||
with storage.pool.connection() as conn:
|
||||
attachment = conn.execute('SELECT * FROM attachments WHERE id=%s FOR UPDATE',
|
||||
(attachment_id,)).fetchone()
|
||||
if not attachment:
|
||||
return None
|
||||
job = conn.execute('SELECT * FROM attachment_jobs WHERE attachment_id=%s AND pipeline_version=%s FOR UPDATE',
|
||||
(attachment_id, attachment['target_pipeline_version'])).fetchone()
|
||||
if not job or job['state'] != 'failed':
|
||||
return None
|
||||
source = attachment['object_key'] if attachment['published_pipeline_version'] else job['staging_key']
|
||||
object_lock(conn, source)
|
||||
client().head_object(Bucket=BUCKET, Key=source)
|
||||
new_attempt = job['attempt'] + 1
|
||||
budget = int(setting('JOB_MAX_ATTEMPTS', '5'))
|
||||
conn.execute(
|
||||
"""UPDATE attachment_jobs SET state='queued', attempt=%s, attempt_limit=%s,
|
||||
next_publish_at=clock_timestamp(), published_at=NULL, publish_failures=0, settled_at=NULL
|
||||
WHERE id=%s""", (new_attempt, new_attempt + budget - 1, job['id']),
|
||||
)
|
||||
conn.execute("INSERT INTO attachment_replays(job_id,attempt,reason) VALUES (%s,%s,'operator')",
|
||||
(job['id'], new_attempt))
|
||||
conn.execute("UPDATE attachments SET state='queued',error_code=NULL,updated_at=clock_timestamp() "
|
||||
"WHERE id=%s AND published_pipeline_version IS NULL", (attachment_id,))
|
||||
return job['id'], new_attempt
|
||||
|
||||
|
||||
def upgrade(attachment_id, version):
|
||||
with storage.pool.connection() as conn:
|
||||
attachment = conn.execute('SELECT * FROM attachments WHERE id=%s FOR UPDATE', (attachment_id,)).fetchone()
|
||||
if not attachment or version not in ENCODING or version <= attachment['target_pipeline_version']:
|
||||
return None
|
||||
previous = conn.execute(
|
||||
'SELECT staging_key FROM attachment_jobs WHERE attachment_id=%s AND pipeline_version=%s',
|
||||
(attachment_id, attachment['target_pipeline_version']),
|
||||
).fetchone()
|
||||
if not previous and not attachment['published_pipeline_version']:
|
||||
return None
|
||||
source = attachment['object_key'] if attachment['published_pipeline_version'] else previous['staging_key']
|
||||
object_lock(conn, source)
|
||||
client().head_object(Bucket=BUCKET, Key=source)
|
||||
conn.execute(
|
||||
"""UPDATE attachment_jobs SET state='superseded', lease_token=NULL, lease_until=NULL,
|
||||
next_publish_at=NULL, settled_at=clock_timestamp()
|
||||
WHERE attachment_id=%s AND state IN ('queued','processing')""", (attachment_id,),
|
||||
)
|
||||
conn.execute(
|
||||
"""UPDATE attachments SET target_pipeline_version=%s,
|
||||
state=CASE WHEN published_pipeline_version IS NULL THEN 'queued' ELSE 'ready' END,
|
||||
error_code=NULL,updated_at=clock_timestamp() WHERE id=%s""",
|
||||
(version, attachment_id),
|
||||
)
|
||||
job_id = uuid4()
|
||||
conn.execute(
|
||||
"""INSERT INTO attachment_jobs(id,attachment_id,staging_key,attempt_limit,next_publish_at,pipeline_version)
|
||||
VALUES (%s,%s,%s,%s,clock_timestamp(),%s)""",
|
||||
(job_id, attachment_id, f'staging/{attachment_id}', int(setting('JOB_MAX_ATTEMPTS', '5')), version),
|
||||
)
|
||||
return job_id
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
"""Единственный обязательный pipeline."""
|
||||
"""Required pipeline only."""
|
||||
ENCODING = {1: (85, 82)}
|
||||
|
||||
@@ -18,6 +18,3 @@ def readiness():
|
||||
return Health()
|
||||
|
||||
|
||||
@router.get('/stats')
|
||||
def stats():
|
||||
return storage.get_stats()
|
||||
|
||||
Reference in New Issue
Block a user