Отделить обработку вложений от приёма файла.

Upload отвечает 202 после staging и записи задания, worker через RabbitMQ собирает thumbnail, crop и optimized и переживает разрыв до publish.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-09 01:08:24 +03:00
co-authored by Cursor
parent 9046d5206d
commit f2a3698480
24 changed files with 1579 additions and 82 deletions
+6 -2
View File
@@ -9,6 +9,7 @@ from uuid import UUID, uuid4
from app import config, db, images, s3
from app.attachments import _compensate, _public
from app import jobs
from app.errors import AppError
from app.store import format_ts
@@ -159,7 +160,7 @@ async def complete_upload(upload_id: str, owner_id: str, claimed_sha: str) -> di
id, chat_id, owner_id, filename, content_type, size_bytes,
sha256, object_key, status, error_code, created_at, updated_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'ready', NULL, $9, $9)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'queued', NULL, $9, $9)
""",
row["id"],
row["chat_id"],
@@ -171,6 +172,7 @@ async def complete_upload(upload_id: str, owner_id: str, claimed_sha: str) -> di
row["object_key"],
created,
)
await jobs.insert_job(conn, row["id"], created)
await conn.execute(
"UPDATE blob_writes SET committed = TRUE WHERE object_key = $1",
row["object_key"],
@@ -183,6 +185,7 @@ async def complete_upload(upload_id: str, owner_id: str, claimed_sha: str) -> di
raise
except Exception:
raise AppError(503, "service unavailable") from None
jobs.kick_publish()
return _public(
{
"id": row["id"],
@@ -192,7 +195,8 @@ async def complete_upload(upload_id: str, owner_id: str, claimed_sha: str) -> di
"content_type": row["content_type"],
"size_bytes": len(data),
"sha256": digest,
"status": "ready",
"status": "queued",
"error_code": None,
"created_at": created,
"updated_at": created,
}