Добавить версионированный pipeline и проверку идемпотентности.

Трек 2 фиксирует дубль, устаревшую версию, падение до и после записи объекта и replay без второй копии результата.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-09 01:23:49 +03:00
co-authored by Cursor
parent 5617dca7d2
commit cf9d9a918f
10 changed files with 641 additions and 72 deletions
+63 -1
View File
@@ -2,6 +2,8 @@ import base64
import binascii
import re
from uuid import UUID
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
@@ -398,9 +400,10 @@ async def download_attachment(request: Request) -> Response:
"""
SELECT content_type, object_key
FROM attachment_variants
WHERE attachment_id = $1 AND pipeline_version = 1 AND name = $2
WHERE attachment_id = $1 AND pipeline_version = $2 AND name = $3
""",
row["id"],
int(row["applied_pipeline_version"]),
variant,
)
if found is None:
@@ -410,6 +413,65 @@ async def download_attachment(request: Request) -> Response:
return Response(payload, status_code=200, media_type=media_type, headers={"X-Request-Id": rid})
async def lab_fault(request: Request) -> Response:
rid = request.state.request_id
if not config.lab_mode():
return error_response(404, "not found", rid)
raw = await request.body()
body, err = parse_json_body(raw)
if err:
return error_response(400, err, rid)
assert body is not None
mode = body.get("mode", "")
remaining = body.get("remaining", 1)
if isinstance(remaining, bool) or not isinstance(remaining, int):
return error_response(400, "invalid fault", rid)
try:
armed = await jobs.arm_fault(mode, remaining)
except AppError as exc:
return error_response(exc.status, exc.message, rid)
return _json(armed, rid)
async def lab_jobs(request: Request) -> Response:
rid = request.state.request_id
if not config.lab_mode():
return error_response(404, "not found", rid)
attachment_id = request.path_params["attachment_id"]
if validate_uuid(attachment_id):
return error_response(400, "invalid attachment id", rid)
listed = await jobs.list_jobs(UUID(attachment_id))
if listed["applied_pipeline_version"] is None:
return error_response(404, "attachment not found", rid)
return _json(listed, rid)
async def lab_bump(request: Request) -> Response:
rid = request.state.request_id
if not config.lab_mode():
return error_response(404, "not found", rid)
attachment_id = request.path_params["attachment_id"]
if validate_uuid(attachment_id):
return error_response(400, "invalid attachment id", rid)
result = await jobs.bump_pipeline(UUID(attachment_id))
if result["result"] == "missing":
return error_response(404, "attachment not found", rid)
return _json(result, rid, 202)
async def lab_redeliver(request: Request) -> Response:
rid = request.state.request_id
if not config.lab_mode():
return error_response(404, "not found", rid)
job_id = request.path_params["job_id"]
if validate_uuid(job_id):
return error_response(400, "invalid job id", rid)
result = await jobs.redeliver(UUID(job_id))
if result["result"] == "missing":
return error_response(404, "attachment not found", rid)
return _json(result, rid, 202)
async def lab_replay(request: Request) -> Response:
rid = request.state.request_id
if not config.lab_mode():