Use NullPool for Celery workers so connections are opened/closed per task instead of accumulating in per-process pools. Add worker_process_init signal to dispose inherited engines on fork. Keep QueuePool for the web service. Increase PostgreSQL max_connections to 200 as a safety net. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
121 lines
3.8 KiB
YAML
121 lines
3.8 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
web:
|
|
build: .
|
|
ports:
|
|
- "8000:8000"
|
|
environment:
|
|
- DATABASE_URL=postgresql://pah:pah_password@db:5432/pah
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- CELERY_BROKER_URL=redis://redis:6379/0
|
|
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
|
- SONAUTO_API_KEY=${SONAUTO_API_KEY}
|
|
- SONAUTO_API_URL=https://api.sonauto.ai/v1
|
|
- WEBHOOK_BASE_URL=${WEBHOOK_BASE_URL}
|
|
- GOOGLE_APPLICATION_CREDENTIALS=/app/google_cloud_storage.json
|
|
- DB_POOL_CLASS=QueuePool
|
|
- DB_POOL_SIZE=5
|
|
- DB_MAX_OVERFLOW=10
|
|
volumes:
|
|
- ./google_cloud_storage.json:/app/google_cloud_storage.json:ro
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_started
|
|
|
|
# Default worker: all tasks except video generation
|
|
celery_worker_default:
|
|
build: .
|
|
command: celery -A tasks.celery_app worker --loglevel=info --concurrency=10 --queues=celery --hostname=worker-default@%h
|
|
environment:
|
|
- DATABASE_URL=postgresql://pah:pah_password@db:5432/pah
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- CELERY_BROKER_URL=redis://redis:6379/0
|
|
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
|
- SONAUTO_API_KEY=${SONAUTO_API_KEY}
|
|
- SONAUTO_API_URL=https://api.sonauto.ai/v1
|
|
- WEBHOOK_BASE_URL=${WEBHOOK_BASE_URL}
|
|
- GOOGLE_APPLICATION_CREDENTIALS=/app/google_cloud_storage.json
|
|
- DB_POOL_CLASS=NullPool
|
|
volumes:
|
|
- ./google_cloud_storage.json:/app/google_cloud_storage.json:ro
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_started
|
|
|
|
# Video worker: dispatches to Cloud Run (high concurrency, HTTP-only)
|
|
celery_worker_video:
|
|
build: .
|
|
command: celery -A tasks.celery_app worker --loglevel=info --concurrency=100 --queues=video --hostname=worker-video@%h
|
|
environment:
|
|
- DATABASE_URL=postgresql://pah:pah_password@db:5432/pah
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- CELERY_BROKER_URL=redis://redis:6379/0
|
|
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
|
- SONAUTO_API_KEY=${SONAUTO_API_KEY}
|
|
- SONAUTO_API_URL=https://api.sonauto.ai/v1
|
|
- WEBHOOK_BASE_URL=${WEBHOOK_BASE_URL}
|
|
- CLOUD_RUN_VIDEO_URL=${CLOUD_RUN_VIDEO_URL}
|
|
- VIDEO_SERVICE_API_KEY=${VIDEO_SERVICE_API_KEY}
|
|
- GOOGLE_APPLICATION_CREDENTIALS=/app/google_cloud_storage.json
|
|
- DB_POOL_CLASS=NullPool
|
|
volumes:
|
|
- ./google_cloud_storage.json:/app/google_cloud_storage.json:ro
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_started
|
|
|
|
celery_beat:
|
|
build: .
|
|
command: celery -A tasks.celery_app beat --loglevel=info
|
|
environment:
|
|
- DATABASE_URL=postgresql://pah:pah_password@db:5432/pah
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- CELERY_BROKER_URL=redis://redis:6379/0
|
|
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
|
- SONAUTO_API_KEY=${SONAUTO_API_KEY}
|
|
- SONAUTO_API_URL=https://api.sonauto.ai/v1
|
|
- WEBHOOK_BASE_URL=${WEBHOOK_BASE_URL}
|
|
- GOOGLE_APPLICATION_CREDENTIALS=/app/google_cloud_storage.json
|
|
- DB_POOL_CLASS=NullPool
|
|
volumes:
|
|
- ./google_cloud_storage.json:/app/google_cloud_storage.json:ro
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_started
|
|
|
|
db:
|
|
image: postgres:15
|
|
environment:
|
|
- POSTGRES_USER=pah
|
|
- POSTGRES_PASSWORD=pah_password
|
|
- POSTGRES_DB=pah
|
|
command: postgres -c max_connections=200
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
ports:
|
|
- "5432:5432"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U pah -d pah"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
ports:
|
|
- "6379:6379"
|
|
volumes:
|
|
- redis_data:/data
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|