|
23 | 23 | _logger = logging.getLogger(__name__) |
24 | 24 |
|
25 | 25 |
|
26 | | -def flush_started_banner() -> None: |
| 26 | +def _flush_started_banner() -> None: |
27 | 27 | # WARNING: this function is spied in the tests |
28 | 28 | print(APP_STARTED_BANNER_MSG, flush=True) # noqa: T201 |
29 | 29 |
|
30 | 30 |
|
31 | | -def flush_finished_banner() -> None: |
| 31 | +def _flush_finished_banner() -> None: |
| 32 | + # WARNING: this function is spied in the tests |
32 | 33 | print(APP_FINISHED_BANNER_MSG, flush=True) # noqa: T201 |
33 | 34 |
|
34 | 35 |
|
35 | | -async def _setup_app(app: FastAPI) -> AsyncIterator[State]: |
36 | | - flush_started_banner() |
| 36 | +async def _banners_lifespan(_) -> AsyncIterator[State]: |
| 37 | + _flush_started_banner() |
| 38 | + yield {} |
| 39 | + _flush_finished_banner() |
| 40 | + |
37 | 41 |
|
| 42 | +async def _main_lifespan(app: FastAPI) -> AsyncIterator[State]: |
38 | 43 | settings: ApplicationSettings = app.state.settings |
39 | 44 |
|
40 | 45 | yield { |
41 | 46 | PostgresLifespanState.POSTGRES_SETTINGS: settings.CATALOG_POSTGRES, |
42 | 47 | "prometheus_instrumentation_enabled": settings.CATALOG_PROMETHEUS_INSTRUMENTATION_ENABLED, |
43 | 48 | } |
44 | 49 |
|
45 | | - flush_finished_banner() |
46 | 50 |
|
47 | | - |
48 | | -async def _setup_prometheus_instrumentation_adapter( |
| 51 | +async def _prometheus_instrumentation_lifespan( |
49 | 52 | app: FastAPI, state: State |
50 | 53 | ) -> AsyncIterator[State]: |
51 | | - enabled = state.get("prometheus_instrumentation_enabled", False) |
52 | | - if enabled: |
| 54 | + if state.get("prometheus_instrumentation_enabled", False): |
53 | 55 | async for prometheus_state in lifespan_prometheus_instrumentation(app): |
54 | 56 | yield prometheus_state |
55 | 57 |
|
56 | 58 |
|
57 | 59 | def create_app_lifespan(): |
58 | | - # app lifespan |
59 | | - app_lifespan = LifespanManager() |
60 | | - app_lifespan.add(_setup_app) |
61 | | - |
62 | 60 | # WARNING: order matters |
| 61 | + app_lifespan = LifespanManager() |
| 62 | + app_lifespan.add(_main_lifespan) |
63 | 63 |
|
64 | | - # - postgres lifespan |
| 64 | + # - postgres |
65 | 65 | app_lifespan.add(postgres_database_lifespan) |
66 | 66 | app_lifespan.add(database_lifespan) |
67 | 67 |
|
68 | | - # - rabbitmq lifespan |
| 68 | + # - rabbitmq |
69 | 69 | app_lifespan.add(rabbitmq_lifespan) |
70 | 70 |
|
71 | | - # - rpc api routes lifespan |
| 71 | + # - rpc api routes |
72 | 72 | app_lifespan.add(rpc_api_lifespan) |
73 | 73 |
|
74 | | - # - director lifespan |
| 74 | + # - director |
75 | 75 | app_lifespan.add(director_lifespan) |
76 | 76 |
|
77 | | - # - function services lifespan |
| 77 | + # - function services |
78 | 78 | app_lifespan.add(function_services_lifespan) |
79 | 79 |
|
80 | | - # - background task lifespan |
| 80 | + # - background task |
81 | 81 | app_lifespan.add(background_task_lifespan) |
82 | 82 |
|
83 | | - # - prometheus instrumentation lifespan |
84 | | - app_lifespan.add(_setup_prometheus_instrumentation_adapter) |
| 83 | + # - prometheus instrumentation |
| 84 | + app_lifespan.add(_prometheus_instrumentation_lifespan) |
| 85 | + |
| 86 | + app_lifespan.add(_banners_lifespan) |
85 | 87 |
|
86 | 88 | return app_lifespan |
0 commit comments