-
Notifications
You must be signed in to change notification settings - Fork 0
chore: removal of nullable fields #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HardMax71
wants to merge
21
commits into
main
Choose a base branch
from
removal-of-nullable-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
df9a229
user settings update: init moved to providers
HardMax71 6d151b9
notification service: update and removal of initialize()
HardMax71 1aa1377
event bus: removal of manager (bus is passed directly)
HardMax71 caf1422
sse service: removed getattr
HardMax71 22c0554
removed LifecycleEnabled - we have DI and handling stuff via _aenter …
HardMax71 f5ca16d
tests update
HardMax71 ff45a52
Di usage instead of stateful services
HardMax71 66456d0
Di usage instead of stateful services
HardMax71 a5c9e97
moved lifetime mgmt to DI
HardMax71 a994a84
moved all inits to providers, simplified all other stuff
HardMax71 e7f2228
test infra updates - using beanie instead of mongodb driver
HardMax71 583c5ff
more event-based stuff, removed all loops except 2 for notif service
HardMax71 62c375c
tests fixes
HardMax71 afdc672
tests fixes
HardMax71 6a3a161
added missing providers
HardMax71 594b4ad
lifespan fixes
HardMax71 b599e71
faststream decode func fix
HardMax71 fd3c18c
removed coordinator block - now load is handled inside kafka/redis
HardMax71 ef7c044
updated docs, updated AckPolicy for workers, updated log level for sc…
HardMax71 5a9fdc0
dumb error fix
HardMax71 4b104db
filter by event type
HardMax71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,110 +1,11 @@ | ||
| import asyncio | ||
| import logging | ||
| from contextlib import AsyncExitStack, asynccontextmanager | ||
| from typing import AsyncGenerator | ||
| from collections.abc import AsyncGenerator | ||
| from contextlib import asynccontextmanager | ||
|
|
||
| import redis.asyncio as redis | ||
| from beanie import init_beanie | ||
| from dishka import AsyncContainer | ||
| from fastapi import FastAPI | ||
|
|
||
| from app.core.database_context import Database | ||
| from app.core.metrics import RateLimitMetrics | ||
| from app.core.startup import initialize_rate_limits | ||
| from app.core.tracing import init_tracing | ||
| from app.db.docs import ALL_DOCUMENTS | ||
| from app.events.event_store_consumer import EventStoreConsumer | ||
| from app.events.schema.schema_registry import SchemaRegistryManager, initialize_event_schemas | ||
| from app.services.sse.kafka_redis_bridge import SSEKafkaRedisBridge | ||
| from app.settings import Settings | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: | ||
| """ | ||
| Application lifespan with dishka dependency injection. | ||
|
|
||
| This is much cleaner than the old lifespan.py: | ||
| - No dependency_overrides | ||
| - No manual service management | ||
| - Dishka handles all lifecycle automatically | ||
| """ | ||
| # Get settings and logger from DI container (uses test settings in tests) | ||
| container: AsyncContainer = app.state.dishka_container | ||
| settings = await container.get(Settings) | ||
| logger = await container.get(logging.Logger) | ||
|
|
||
| logger.info( | ||
| "Starting application with dishka DI", | ||
| extra={ | ||
| "project_name": settings.PROJECT_NAME, | ||
| "environment": "test" if settings.TESTING else "production", | ||
| }, | ||
| ) | ||
|
|
||
| # Metrics setup moved to app creation to allow middleware registration | ||
| logger.info("Lifespan start: tracing and services initialization") | ||
|
|
||
| # Initialize tracing only when enabled (avoid exporter retries in tests) | ||
| if settings.ENABLE_TRACING and not settings.TESTING: | ||
| instrumentation_report = init_tracing( | ||
| service_name=settings.TRACING_SERVICE_NAME, | ||
| settings=settings, | ||
| logger=logger, | ||
| service_version=settings.TRACING_SERVICE_VERSION, | ||
| sampling_rate=settings.TRACING_SAMPLING_RATE, | ||
| enable_console_exporter=settings.TESTING, | ||
| adaptive_sampling=settings.TRACING_ADAPTIVE_SAMPLING, | ||
| ) | ||
|
|
||
| if instrumentation_report.has_failures(): | ||
| logger.warning( | ||
| "Some instrumentation libraries failed to initialize", | ||
| extra={"instrumentation_summary": instrumentation_report.get_summary()}, | ||
| ) | ||
| else: | ||
| logger.info( | ||
| "Distributed tracing initialized successfully", | ||
| extra={"instrumentation_summary": instrumentation_report.get_summary()}, | ||
| ) | ||
| else: | ||
| logger.info( | ||
| "Distributed tracing disabled", | ||
| extra={"testing": settings.TESTING, "enable_tracing": settings.ENABLE_TRACING}, | ||
| ) | ||
|
|
||
| # Phase 1: Resolve all DI dependencies in parallel | ||
| ( | ||
| schema_registry, | ||
| database, | ||
| redis_client, | ||
| rate_limit_metrics, | ||
| sse_bridge, | ||
| event_store_consumer, | ||
| ) = await asyncio.gather( | ||
| container.get(SchemaRegistryManager), | ||
| container.get(Database), | ||
| container.get(redis.Redis), | ||
| container.get(RateLimitMetrics), | ||
| container.get(SSEKafkaRedisBridge), | ||
| container.get(EventStoreConsumer), | ||
| ) | ||
|
|
||
| # Phase 2: Initialize infrastructure in parallel (independent subsystems) | ||
| await asyncio.gather( | ||
| initialize_event_schemas(schema_registry), | ||
| init_beanie(database=database, document_models=ALL_DOCUMENTS), | ||
| initialize_rate_limits(redis_client, settings, logger, rate_limit_metrics), | ||
| ) | ||
| logger.info("Infrastructure initialized (schemas, beanie, rate limits)") | ||
|
|
||
| # Phase 3: Start Kafka consumers in parallel | ||
| async with AsyncExitStack() as stack: | ||
| stack.push_async_callback(sse_bridge.aclose) | ||
| stack.push_async_callback(event_store_consumer.aclose) | ||
| await asyncio.gather( | ||
| sse_bridge.__aenter__(), | ||
| event_store_consumer.__aenter__(), | ||
| ) | ||
| logger.info("SSE bridge and EventStoreConsumer started") | ||
| yield | ||
| """Minimal lifespan - container.close() triggers all provider cleanup.""" | ||
| yield | ||
| await app.state.dishka_container.close() | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.