Forward the lab 5 foundation while preserving lab 6 telemetry

Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files.

Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
This commit is contained in:
Artyom
2026-11-06 12:29:35 +03:00
parent dc9256baf9
commit 12db77133f
161 changed files with 11160 additions and 1467 deletions
@@ -33,6 +33,15 @@ class JobSettled(DomainEvent):
name: str = field(init=False, default="job.settled")
@dataclass(frozen=True, slots=True)
class AttachmentReprocessRequested(DomainEvent):
attachment_id: UUID
pipeline_version: int
operator: str
result: str
name: str = field(init=False, default="attachment.reprocess_requested")
@dataclass(frozen=True, slots=True)
class AttachmentReplayRequested(DomainEvent):
attachment_id: UUID
+8
View File
@@ -6,6 +6,7 @@ from uuid import UUID
JOB_TYPE = "attachment.process.v1"
SCHEMA_VERSION = 1
PIPELINE_VERSIONS = (1, 2)
class FailureCode(StrEnum):
@@ -21,6 +22,13 @@ class ReplayResult(StrEnum):
NOT_FOUND = "not_found"
class ReprocessResult(StrEnum):
QUEUED = "queued"
NOOP = "noop"
CONFLICT = "conflict"
NOT_FOUND = "not_found"
class Outcome(StrEnum):
DONE = "done"
DUPLICATE = "duplicate_noop"
@@ -8,6 +8,7 @@ from messenger.attachments.domain.values import Filename, ImageInfo
from messenger.attachments.domain.variants import Variant
from messenger.shared.domain.events import DomainEvent
OBJECT_PREFIX = "attachments/"
STAGING_PREFIX = "staging/"
ORIGINALS_PREFIX = "originals/"
@@ -24,6 +25,12 @@ def original_key(attachment_id: UUID) -> str:
return f"{ORIGINALS_PREFIX}{attachment_id}"
class Quarantine(StrEnum):
MISSING = "missing"
SIZE_MISMATCH = "size_mismatch"
SHA_MISMATCH = "sha_mismatch"
@dataclass(slots=True)
class Attachment:
id: UUID
@@ -41,6 +48,7 @@ class Attachment:
published_version: int = 0
error_code: str | None = None
variants: tuple[Variant, ...] = ()
quarantine: Quarantine | None = None
_events: list[DomainEvent] = field(init=False, default_factory=list, repr=False, compare=False)
@classmethod
@@ -70,6 +78,10 @@ class Attachment:
staging_key=f"{STAGING_PREFIX}{attachment_id}",
)
@property
def object_key(self) -> str:
return self.original_key or self.staging_key or f"{OBJECT_PREFIX}{self.id}"
@property
def content_type(self) -> str:
return self.image.kind.value
@@ -98,6 +110,13 @@ class Attachment:
AttachmentDiscarded(attachment_id=self.id, chat_id=self.chat_id, reason=reason)
)
def isolate(self, reason: Quarantine) -> None:
if self.status is AttachmentStatus.READY:
self.quarantine = reason
def release(self) -> None:
self.quarantine = None
def collect_events(self) -> list[DomainEvent]:
events, self._events = self._events, []
return events