Skip to content

Commit f0a863d

Browse files
chore: add health and readiness probes (#15)
1 parent 59f2196 commit f0a863d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

docker-compose.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ services:
7070
migration:
7171
condition: service_completed_successfully
7272
healthcheck:
73-
test: ["CMD-SHELL", "curl -f http://localhost:8080/docs || exit 1"]
73+
test: ["CMD-SHELL", "curl -f http://localhost:8080/ready || exit 1"]
7474
interval: 5s
7575
timeout: 10s
7676
retries: 10

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ services:
6363
migration:
6464
condition: service_completed_successfully
6565
healthcheck:
66-
test: ["CMD-SHELL", "curl -f http://localhost:8080/docs || exit 1"]
66+
test: ["CMD-SHELL", "curl -f http://localhost:8080/ready || exit 1"]
6767
interval: 10s
6868
timeout: 10s
6969
retries: 5

strava/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from contextlib import asynccontextmanager
22

3-
from fastapi import APIRouter, FastAPI
3+
from fastapi import APIRouter, Depends, FastAPI
4+
from sqlalchemy import text
5+
from sqlalchemy.orm import Session
46

57
from strava.config import settings
8+
from strava.db.depends import get_db
69
from strava.db.session import engine
710
from strava.observability import configure_observability
811
from strava.routes import routes
@@ -21,3 +24,14 @@ async def lifespan(_: FastAPI):
2124
app = FastAPI(title=settings.PROJECT_NAME, lifespan=lifespan)
2225
configure_observability(app, settings, engine)
2326
app.include_router(v1_router, prefix=settings.API_V1_STR)
27+
28+
29+
@app.get("/health")
30+
async def health():
31+
return {"status": "ok"}
32+
33+
34+
@app.get("/ready")
35+
def ready(db: Session = Depends(get_db)):
36+
db.execute(text("SELECT 1"))
37+
return {"status": "ok"}

0 commit comments

Comments
 (0)