Skip to content

Commit 040f31b

Browse files
committed
build: add healthchecks for services
add healthchecks for postgres, redis and celery worker. Change depends_on condition for postgres and redis to service_healthy. Add timeout config to gunicorn config to fix gunicorn worker exiting due to [CRITICAL] WORKER TIMEOUT Error handling request (no URI read).
1 parent 02db3ec commit 040f31b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

docker-compose.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ x-app: &default-app
99
- "NODE_ENV=${NODE_ENV:-production}"
1010
depends_on:
1111
postgres:
12-
condition: "service_started"
12+
condition: "service_healthy"
1313
required: false
1414
redis:
15-
condition: "service_started"
15+
condition: "service_healthy"
1616
required: false
1717
env_file:
1818
- ".env"
@@ -49,11 +49,16 @@ services:
4949
environment:
5050
POSTGRES_USER: "${POSTGRES_USER}"
5151
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
52-
# POSTGRES_DB: "${POSTGRES_DB}"
52+
POSTGRES_DB: "${POSTGRES_DB}"
5353
image: "postgres:16.3-bookworm"
5454
profiles: ["postgres"]
5555
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"
5656
stop_grace_period: "3s"
57+
healthcheck:
58+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
59+
interval: 5s
60+
timeout: 5s
61+
retries: 5
5762
volumes:
5863
- "postgres:/var/lib/postgresql/data"
5964

@@ -67,6 +72,11 @@ services:
6772
profiles: ["redis"]
6873
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"
6974
stop_grace_period: "3s"
75+
healthcheck:
76+
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
77+
interval: 1s
78+
timeout: 3s
79+
retries: 5
7080
volumes:
7181
- "redis:/data"
7282

@@ -96,6 +106,12 @@ services:
96106
limits:
97107
cpus: "${DOCKER_WORKER_CPUS:-0}"
98108
memory: "${DOCKER_WORKER_MEMORY:-0}"
109+
healthcheck:
110+
test: ["CMD-SHELL", "celery -b ${REDIS_URL:-redis://redis:6379/0} inspect ping -d celery@$$HOSTNAME"]
111+
interval: 30s
112+
timeout: 10s
113+
retries: 3
114+
start_period: 10s
99115
profiles: ["worker"]
100116

101117
js:

src/config/gunicorn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
threads = int(os.getenv("PYTHON_MAX_THREADS", 1))
1313

1414
reload = bool(strtobool(os.getenv("WEB_RELOAD", "false")))
15+
16+
timeout = 120

0 commit comments

Comments
 (0)