feat: reconcile the bucket against attachment rows in the cleaner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@ from .attachment import (
|
||||
AttachmentFullDTO,
|
||||
AttachmentInListDTO,
|
||||
CleanupPassDTO,
|
||||
ReconcileFindingDTO,
|
||||
ReconcilePassDTO,
|
||||
)
|
||||
from .chat import ChatFullDTO, ChatPageDTO
|
||||
from .idempotency import IdempotencyRecordDTO
|
||||
@@ -21,6 +23,8 @@ __all__ = [
|
||||
"IdempotencyRecordDTO",
|
||||
"MessageFullDTO",
|
||||
"MessagePageDTO",
|
||||
"ReconcileFindingDTO",
|
||||
"ReconcilePassDTO",
|
||||
"SessionFullDTO",
|
||||
"SessionTokenDTO",
|
||||
"UserCredentialsDTO",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from collections.abc import AsyncIterator, Awaitable, Callable
|
||||
from collections.abc import AsyncIterator, Awaitable, Callable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from src.schemas.enums import AttachmentStatus, ImageType
|
||||
from src.schemas.enums import AttachmentStatus, ImageType, ReconcileFinding
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -11,7 +11,9 @@ class AttachmentFullDTO:
|
||||
"""Строка вложения: метаданные и ключ объекта в S3.
|
||||
|
||||
`object_key` и статус `pending` в API не попадают; `sha256` — байты
|
||||
SHA-256 оригинала, hex собирает модель ответа.
|
||||
SHA-256 оригинала, hex собирает модель ответа. `lost_at` — когда сверка
|
||||
подтвердила потерю оригинала (design change `track2-reconciler`,
|
||||
решение 5); в ответы API не попадает.
|
||||
"""
|
||||
|
||||
id: UUID
|
||||
@@ -25,6 +27,7 @@ class AttachmentFullDTO:
|
||||
status: AttachmentStatus
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
lost_at: datetime | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -54,6 +57,52 @@ class CleanupPassDTO:
|
||||
duration_ms: int
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class ReconcileFindingDTO:
|
||||
"""Расхождение bucket и БД, найденное сверкой (design change
|
||||
`track2-reconciler`, решение 8).
|
||||
|
||||
`attachment_id` — если известен (из ключа или строки), `age_seconds` —
|
||||
возраст объекта (`LastModified`) или строки (`updated_at` у ready,
|
||||
`created_at` у pending). `size_bytes` и `stored_size` — размеры строки и
|
||||
объекта, если известны оба.
|
||||
"""
|
||||
|
||||
kind: ReconcileFinding
|
||||
object_key: str
|
||||
attachment_id: UUID | None
|
||||
age_seconds: int
|
||||
size_bytes: int | None = None
|
||||
stored_size: int | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class ReconcilePassDTO:
|
||||
"""Итог прохода сверки.
|
||||
|
||||
`found` и `fixed` — подтверждённые и исправленные расхождения по
|
||||
классам (неизменяемые отображения), `remaining` — сколько осталось.
|
||||
`refused` — `--apply` отказался по пределу изменений, `unlogged` —
|
||||
сколько расхождений не записано отдельными записями,
|
||||
`interrupted_by` — причина прерывания (`object_storage`, `database`,
|
||||
`stop`) или `None`.
|
||||
"""
|
||||
|
||||
apply: bool
|
||||
listed_objects: int
|
||||
checked_rows: int
|
||||
found: Mapping[ReconcileFinding, int]
|
||||
fixed: Mapping[ReconcileFinding, int]
|
||||
remaining: int
|
||||
fresh_objects: int
|
||||
fresh_rows: int
|
||||
lost_known: int
|
||||
refused: bool
|
||||
unlogged: int
|
||||
interrupted_by: str | None
|
||||
duration_ms: int
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class AttachmentContentDTO:
|
||||
"""Оригинал вложения на отдачу потоком.
|
||||
|
||||
Reference in New Issue
Block a user