lab5 API: upload 202 queued через staging + задание + outbox одной транзакцией

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Порядок: pending-намерение -> PUT в приватный staging bucket -> COMMIT queued + jobs + outbox
-> 202. Проверки 413/415 lab4 остаются синхронными. GET видит queued/processing/failed,
content: 409 до ready, варианты thumbnail/crop/optimized; к сообщению можно прикрепить
queued/processing, failed -> 409. API не связан с брокером.
This commit is contained in:
Alexey Bodanyuk
2026-10-31 16:12:52 +03:00
parent a633949919
commit 655f264104
6 changed files with 176 additions and 104 deletions
+14 -3
View File
@@ -58,8 +58,10 @@ class ListedObject:
class Storage:
def __init__(self, settings: Settings, *, access_key: str | None = None, secret_key: str | None = None):
self.bucket = settings.s3_bucket
def __init__(self, settings: Settings, *, access_key: str | None = None, secret_key: str | None = None,
bucket: str | None = None):
# Lab 5: one client per bucket - the final bucket (S3_BUCKET) or the staging bucket.
self.bucket = bucket or settings.s3_bucket
self.timeout = settings.s3_timeout_seconds
self._endpoint = settings.s3_endpoint
self._region = settings.s3_region
@@ -174,4 +176,13 @@ class Storage:
SENTINEL_KEY = "health/sentinel"
OBJECT_PREFIX = "o/" # every attachment original lives under o/<random 128-bit hex>
# Lab 4 originals: o/<random 128-bit hex> in the final bucket (still readable).
OBJECT_PREFIX = "o/"
# Lab 5: s/<random 128-bit hex> in the STAGING bucket (written by the API before 202) and
# a/<attachment id>/<attempt token>/<original|thumbnail|crop|optimized> in the final bucket
# (written by the worker; the token makes every attempt write its own keys).
STAGING_PREFIX = "s/"
def attempt_key(attachment_id: str, token: str, name: str) -> str:
return f"a/{attachment_id}/{token}/{name}"