Skip to content

Commit f11f14a

Browse files
author
Andrei Neagu
committed
refactor
1 parent 574934b commit f11f14a

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

services/notifications/src/simcore_service_notifications/api/rest/_health.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
)
1010
from servicelib.rabbitmq import RabbitMQClient
1111

12-
from ...services.postgres import PostgresHealth
13-
from .dependencies import get_postgres_health, get_rabbitmq_client
12+
from ...services.postgres import PostgresLiveness
13+
from .dependencies import get_postgres_liveness, get_rabbitmq_client
1414

1515
router = APIRouter()
1616

@@ -22,12 +22,12 @@ class HealthCheckError(RuntimeError):
2222
@router.get("/", response_model=HealthCheckGet)
2323
async def check_service_health(
2424
rabbitmq_client: Annotated[RabbitMQClient, Depends(get_rabbitmq_client)],
25-
postgres_health: Annotated[PostgresHealth, Depends(get_postgres_health)],
25+
postgres_liveness: Annotated[PostgresLiveness, Depends(get_postgres_liveness)],
2626
):
2727
if not rabbitmq_client.healthy:
2828
raise HealthCheckError(RABBITMQ_CLIENT_UNHEALTHY_MSG)
2929

30-
if not postgres_health.is_responsive:
30+
if not postgres_liveness.is_responsive:
3131
raise HealthCheckError(POSRGRES_DATABASE_UNHEALTHY_MSG)
3232

3333
return HealthCheckGet(timestamp=f"{__name__}@{arrow.utcnow().datetime.isoformat()}")

services/notifications/src/simcore_service_notifications/api/rest/dependencies.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from fastapi import Depends, FastAPI, Request
66
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
77

8-
from ...services.postgres import PostgresHealth
9-
from ...services.postgres import get_postgres_health as get_postgress_db_health
8+
from ...services.postgres import PostgresLiveness
9+
from ...services.postgres import get_postgres_liveness as get_postgress_db_liveness
1010

1111

1212
def get_application(request: Request) -> FastAPI:
@@ -20,7 +20,7 @@ def get_rabbitmq_client(
2020
return app.state.rabbitmq_rpc_server
2121

2222

23-
def get_postgres_health(
23+
def get_postgres_liveness(
2424
app: Annotated[FastAPI, Depends(get_application)],
25-
) -> PostgresHealth:
26-
return get_postgress_db_health(app)
25+
) -> PostgresLiveness:
26+
return get_postgress_db_liveness(app)

services/notifications/src/simcore_service_notifications/services/postgres/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
from servicelib.fastapi.postgres_lifespan import PostgresLifespanState
77
from servicelib.logging_utils import log_context
88

9-
from ...core.settings import ApplicationSettings
10-
from ._health import PostgresHealth
9+
from ._liveness import PostgresLiveness
1110

1211
_logger = logging.getLogger(__name__)
1312

1413

1514
async def postgres_lifespan(app: FastAPI, state: State) -> AsyncIterator[State]:
1615
app.state.engine = state[PostgresLifespanState.POSTGRES_ASYNC_ENGINE]
1716

18-
app.state.postgres_health = PostgresHealth(app)
17+
app.state.postgres_health = PostgresLiveness(app)
1918

2019
with log_context(_logger, logging.INFO, msg="setup postgres health"):
2120
await app.state.postgres_health.setup()
@@ -26,9 +25,9 @@ async def postgres_lifespan(app: FastAPI, state: State) -> AsyncIterator[State]:
2625
await app.state.postgres_health.teardown()
2726

2827

29-
def get_postgres_health(app: FastAPI) -> PostgresHealth:
30-
assert isinstance(app.state.postgres_health, PostgresHealth) # nosec
28+
def get_postgres_liveness(app: FastAPI) -> PostgresLiveness:
29+
assert isinstance(app.state.postgres_health, PostgresLiveness) # nosec
3130
return app.state.postgres_health
3231

3332

34-
__all__: tuple[str, ...] = ("PostgresHealth",)
33+
__all__: tuple[str, ...] = ("PostgresLiveness",)

services/notifications/src/simcore_service_notifications/services/postgres/_health.py renamed to services/notifications/src/simcore_service_notifications/services/postgres/_liveness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
_logger = logging.getLogger(__name__)
1414

1515

16-
class PostgresHealth:
16+
class PostgresLiveness:
1717
def __init__(self, app: FastAPI) -> None:
1818
self.app = app
1919

0 commit comments

Comments
 (0)