forked from mtusi2026/mtusi2026lab6
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user