Carry over the lab 3 solution
Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy and k6 configuration, migrations, hooks, evidence and level 4
scripts and the CI job from the lab 3 solution commit 61c0c28, merge
the lab 3 Makefile targets into the lab 4 skeleton Makefile without
touching its targets, and append the lab 3 solution variables to the
skeleton .env.example. The package and the application follow the
contract version 1.4.0, and the image and the throwaway test containers
are tagged lab4 so they do not collide with a lab 3 stand on the same
host.
This is the starting point of the lab 4 cycle: lint, own tests and the
offline skeleton check pass before any lab 4 change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b0f463ac5c
commit
bf8e4e3cd1
@@ -0,0 +1,54 @@
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
from dishka import Provider, Scope, provide
|
||||
|
||||
from messenger.shared.application.messagebus import EventBus, InMemoryEventPublisher
|
||||
from messenger.shared.application.ports import Clock, EventPublisher, IdGenerator, Logger
|
||||
from messenger.shared.config import PlatformSettings
|
||||
from messenger.shared.infrastructure.clock import MonotonicUtcClock
|
||||
from messenger.shared.infrastructure.ids import Uuid7Generator
|
||||
from messenger.shared.infrastructure.postgres import Database
|
||||
|
||||
|
||||
class PlatformProvider(Provider):
|
||||
def __init__(self, settings: PlatformSettings, logger: Logger) -> None:
|
||||
super().__init__()
|
||||
self._settings = settings
|
||||
self._logger = logger
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def settings(self) -> PlatformSettings:
|
||||
return self._settings
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def logger(self) -> Logger:
|
||||
return self._logger
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def clock(self) -> Clock:
|
||||
return MonotonicUtcClock()
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def ids(self) -> IdGenerator:
|
||||
return Uuid7Generator()
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
async def database(self, settings: PlatformSettings) -> AsyncIterator[Database]:
|
||||
database = Database(
|
||||
settings.database_url.get_secret_value(),
|
||||
max_size=settings.db_pool_max_size,
|
||||
connect_timeout=settings.db_connect_timeout_seconds,
|
||||
acquire_timeout=settings.db_acquire_timeout_seconds,
|
||||
command_timeout=settings.db_command_timeout_seconds,
|
||||
)
|
||||
await database.open()
|
||||
yield database
|
||||
await database.close()
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def event_bus(self, logger: Logger, settings: PlatformSettings) -> EventBus:
|
||||
return EventBus(logger, max_queue=settings.event_queue_max)
|
||||
|
||||
@provide(scope=Scope.APP)
|
||||
def publisher(self, bus: EventBus) -> EventPublisher:
|
||||
return InMemoryEventPublisher(bus)
|
||||
Reference in New Issue
Block a user