Skip to content

Commit a9ecdce

Browse files
committed
✨ Refactor: Rename postgres lifespan manager for consistency across the codebase
1 parent a84e2e7 commit a9ecdce

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

packages/service-library/src/servicelib/fastapi/postgres_lifespan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
_logger = logging.getLogger(__name__)
1313

1414

15-
postgres_lifespan = LifespanManager()
15+
postgres_lifespan_manager = LifespanManager()
1616

1717

1818
class PostgresLifespanStateKeys(str, Enum):
1919
POSTGRES_SETTINGS = "postgres_settings"
2020
POSTGRES_ASYNC_ENGINE = "postgres.async_engine"
2121

2222

23-
@postgres_lifespan.add
23+
@postgres_lifespan_manager.add
2424
async def setup_postgres_database(_, state: State) -> AsyncIterator[State]:
2525

2626
with log_context(_logger, logging.INFO, f"{__name__}"):

packages/service-library/tests/fastapi/test_lifespan_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def cache_lifespan(app: FastAPI) -> AsyncIterator[State]:
5353

5454

5555
@pytest.fixture
56-
def postgres_lifespan() -> LifespanManager:
56+
def postgres_lifespan_mng() -> LifespanManager:
5757
lifespan_manager = LifespanManager()
5858

5959
@lifespan_manager.add
@@ -91,12 +91,12 @@ async def _setup_rabbitmq(app: FastAPI) -> AsyncIterator[State]:
9191

9292

9393
async def test_app_lifespan_composition(
94-
postgres_lifespan: LifespanManager, rabbitmq_lifespan: LifespanManager
94+
postgres_lifespan_mng: LifespanManager, rabbitmq_lifespan: LifespanManager
9595
):
9696
# The app has its own database and rpc-server to initialize
9797
# this is how you connect the lifespans pre-defined in servicelib
9898

99-
@postgres_lifespan.add
99+
@postgres_lifespan_mng.add
100100
async def setup_database(app: FastAPI, state: State) -> AsyncIterator[State]:
101101

102102
with log_context(logging.INFO, "app database"):
@@ -126,7 +126,7 @@ async def setup_rpc_server(app: FastAPI, state: State) -> AsyncIterator[State]:
126126

127127
# Composes lifepans
128128
app_lifespan = LifespanManager()
129-
app_lifespan.include(postgres_lifespan)
129+
app_lifespan.include(postgres_lifespan_mng)
130130
app_lifespan.include(rabbitmq_lifespan)
131131

132132
app = FastAPI(lifespan=app_lifespan)

packages/service-library/tests/fastapi/test_postgres_lifespan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pytest_simcore.helpers.typing_env import EnvVarsDict
1919
from servicelib.fastapi.postgres_lifespan import (
2020
PostgresLifespanStateKeys,
21-
postgres_lifespan,
21+
postgres_lifespan_manager,
2222
)
2323
from settings_library.application import BaseApplicationSettings
2424
from settings_library.postgres import PostgresSettings
@@ -69,8 +69,8 @@ async def my_database_setup(app: FastAPI, state: State) -> AsyncIterator[State]:
6969
app_lifespan = LifespanManager()
7070
app_lifespan.add(my_app_settings)
7171

72-
postgres_lifespan.add(my_database_setup)
73-
app_lifespan.include(postgres_lifespan)
72+
postgres_lifespan_manager.add(my_database_setup)
73+
app_lifespan.include(postgres_lifespan_manager)
7474

7575
return app_lifespan
7676

services/catalog/src/simcore_service_catalog/core/events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastapi_lifespan_manager import LifespanManager, State
66
from servicelib.fastapi.postgres_lifespan import (
77
PostgresLifespanStateKeys,
8-
postgres_lifespan,
8+
postgres_lifespan_manager,
99
)
1010
from servicelib.fastapi.prometheus_instrumentation import (
1111
lifespan_prometheus_instrumentation,
@@ -66,8 +66,8 @@ def create_app_lifespan():
6666
# WARNING: order matters
6767

6868
# - postgres lifespan
69-
postgres_lifespan.add(setup_database)
70-
app_lifespan.include(postgres_lifespan)
69+
postgres_lifespan_manager.add(setup_database)
70+
app_lifespan.include(postgres_lifespan_manager)
7171

7272
# - rabbitmq lifespan
7373
app_lifespan.add(setup_rabbitmq)

0 commit comments

Comments
 (0)