Skip to content

Commit d0ba852

Browse files
committed
✨ Integrate Redis lifespan management into application settings
1 parent 11db497 commit d0ba852

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
create_prometheus_instrumentationmain_input_state,
1111
prometheus_instrumentation_lifespan,
1212
)
13+
from servicelib.fastapi.redis_lifespan import (
14+
RedisLifespanState,
15+
redis_database_lifespan,
16+
)
17+
from settings_library.redis import RedisDatabase
1318

14-
from .._meta import APP_FINISHED_BANNER_MSG, APP_STARTED_BANNER_MSG
19+
from .._meta import APP_FINISHED_BANNER_MSG, APP_NAME, APP_STARTED_BANNER_MSG
1520
from ..api.rpc.events import rpc_api_lifespan
1621
from ..clients.director import director_lifespan
1722
from ..clients.rabbitmq import rabbitmq_lifespan
@@ -43,6 +48,11 @@ async def _settings_lifespan(app: FastAPI) -> AsyncIterator[State]:
4348
settings: ApplicationSettings = app.state.settings
4449

4550
yield {
51+
**RedisLifespanState(
52+
REDIS_SETTINGS=settings.CATALOG_REDIS,
53+
REDIS_CLIENT_NAME=APP_NAME,
54+
REDIS_CLIENT_DB=RedisDatabase.LOCKS,
55+
).model_dump(),
4656
**create_postgres_database_input_state(settings.CATALOG_POSTGRES),
4757
**create_prometheus_instrumentationmain_input_state(
4858
enabled=settings.CATALOG_PROMETHEUS_INSTRUMENTATION_ENABLED
@@ -70,7 +80,9 @@ def create_app_lifespan() -> LifespanManager:
7080
# - function services
7181
app_lifespan.add(function_services_lifespan)
7282

83+
# - redis
7384
# - background task
85+
app_lifespan.add(redis_database_lifespan)
7486
app_lifespan.add(background_task_lifespan)
7587

7688
# - prometheus instrumentation

services/catalog/tests/unit/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,18 @@ def repository_lifespan_disabled(mocker: MockerFixture):
227227

228228

229229
@pytest.fixture
230-
def background_task_lifespan_disabled(mocker: MockerFixture) -> None:
230+
def redis_lifespan_disabled(mocker: MockerFixture):
231+
mocker.patch.object(
232+
simcore_service_catalog.core.events,
233+
"redis_database_lifespan",
234+
autospec=True,
235+
)
236+
237+
238+
@pytest.fixture
239+
def background_task_lifespan_disabled(
240+
mocker: MockerFixture, redis_lifespan_disabled: None
241+
) -> None:
231242
class MockedBackgroundTaskContextManager:
232243
async def __aenter__(self):
233244
print(

0 commit comments

Comments
 (0)