Carry over the lab 5 solution

Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6, RustFS and RabbitMQ configuration, migrations, hooks,
scenario scripts and the CI job from the lab 5 solution commit 64d5c67,
keep the lab 5 Makefile targets on top of the unchanged skeleton
targets, and append the lab 5 solution variables to the skeleton
.env.example. The package and the application follow the contract
version 1.6.0, and the image, the throwaway test containers and the
broker vhost description are tagged lab6 so they do not collide with a
lab 5 stand on the same host.

This is the starting point of the lab 6 cycle: lint, own tests and the
offline skeleton check pass before any lab 6 change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 03:51:58 +03:00
co-authored by Claude Opus 5.5
parent a0d3947710
commit 5ae3d77152
204 changed files with 18547 additions and 1 deletions
+78
View File
@@ -0,0 +1,78 @@
import asyncio
from collections.abc import Sequence
from dishka import Provider, make_async_container
from dishka_faststream import setup_dishka
from faststream import FastStream
from faststream.rabbit import RabbitBroker
from messenger.attachments.config import PipelineSettings
from messenger.attachments.entrypoints.heartbeat import Heartbeat
from messenger.attachments.entrypoints.ioc import PipelineProvider, WorkerProvider
from messenger.attachments.entrypoints.journal import LOG_FIELDS, subscribe_journal
from messenger.attachments.entrypoints.worker import subscribe
from messenger.shared.application.messagebus import EventBus
from messenger.shared.config import PlatformSettings
from messenger.shared.entrypoints.ioc import PlatformProvider
from messenger.shared.infrastructure.logging import PLATFORM_FIELDS, StructlogLogger
PING_TIMEOUT_SECONDS = 2.0
def create_worker(
*,
platform: PlatformSettings | None = None,
pipeline: PipelineSettings | None = None,
overrides: Sequence[Provider] = (),
) -> FastStream:
platform = platform or PlatformSettings()
pipeline = pipeline or PipelineSettings()
logger = StructlogLogger(level=platform.log_level, allowed_fields=PLATFORM_FIELDS | LOG_FIELDS)
broker = RabbitBroker(
pipeline.broker_url.get_secret_value(),
graceful_timeout=pipeline.shutdown_grace_seconds,
logger=None,
)
subscribe(broker, pipeline.worker_concurrency)
container = make_async_container(
PlatformProvider(platform, logger),
PipelineProvider(pipeline),
WorkerProvider(),
*overrides,
)
heartbeat = Heartbeat(
pipeline.heartbeat_file,
lambda: broker.ping(PING_TIMEOUT_SECONDS),
pipeline.heartbeat_interval_seconds,
logger,
)
app = FastStream(broker, logger=None)
@app.on_startup
async def start_bus() -> None:
bus = await container.get(EventBus)
subscribe_journal(bus, logger)
bus.start()
@app.after_startup
async def started() -> None:
heartbeat.start()
logger.info("worker.started", limit=pipeline.worker_concurrency)
@app.after_shutdown
async def stopped() -> None:
await heartbeat.stop()
await (await container.get(EventBus)).stop()
await container.close()
logger.info("worker.stopped")
setup_dishka(container, app, auto_inject=True)
return app
def main() -> None:
asyncio.run(create_worker().run())
if __name__ == "__main__":
main()