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
+24 -2
View File
@@ -1,4 +1,4 @@
from collections.abc import AsyncIterator
from collections.abc import AsyncIterator, Sequence
from contextlib import asynccontextmanager
from typing import Any
@@ -8,7 +8,7 @@ from botocore.exceptions import BotoCoreError, ClientError
from botocore.handlers import add_expect_header
from messenger.attachments.application.errors import ObjectMissingError
from messenger.attachments.application.ports import ObjectContent
from messenger.attachments.application.ports import ObjectContent, StoredObject
from messenger.shared.application.errors import Unavailable
CHUNK_BYTES = 64 * 1024
@@ -98,6 +98,28 @@ class S3ObjectStorage:
except FAILURES as error:
raise Unavailable("S3 недоступно") from error
async def listing(self, prefix: str, page_size: int) -> AsyncIterator[Sequence[StoredObject]]:
pages = self._client.get_paginator("list_objects_v2").paginate(
Bucket=self._bucket, Prefix=prefix, PaginationConfig={"PageSize": page_size}
)
try:
async for page in pages:
yield [
StoredObject(item["Key"], item["Size"], item["LastModified"])
for item in page.get("Contents", ())
]
except FAILURES as error:
raise Unavailable("S3 недоступно") from error
async def stat(self, key: str) -> StoredObject | None:
try:
head = await self._client.head_object(Bucket=self._bucket, Key=key)
except FAILURES as error:
if missing(error):
return None
raise Unavailable("S3 недоступно") from error
return StoredObject(key, head["ContentLength"], head["LastModified"])
async def _chunks(self, body: Any) -> AsyncIterator[bytes]:
async with body as stream:
async for chunk in stream.iter_chunks(CHUNK_BYTES):