gunicorn/examples/celery_alternative/docker-compose.yml
Benoit Chesneau 17ac6a5254 examples: add celery_alternative example using dirty arbiters
Demonstrates replacing Celery with Gunicorn's dirty arbiters for
background task processing. Includes:

- 4 task workers: Email, Image, Data, Scheduled
- Stateful workers with persistent connections/caches
- Streaming progress for long-running tasks
- Per-app worker allocation
- Flask API with 15+ endpoints
- Docker deployment (single container vs Celery's 4+)
- Unit tests (19 tests) and integration tests
- Migration guide from Celery
2026-02-01 16:51:48 +01:00

80 lines
1.7 KiB
YAML

# Docker Compose for Celery Replacement Example
#
# Notice: Only ONE service needed!
# Compare with typical Celery deployment which requires:
# - web (gunicorn/uvicorn)
# - celery_worker
# - celery_beat (for scheduled tasks)
# - redis or rabbitmq
#
# With dirty arbiters, everything runs in a single container.
services:
app:
build:
context: ../.. # Gunicorn repo root
dockerfile: examples/celery_alternative/Dockerfile
ports:
- "8000:8000"
environment:
- GUNICORN_WORKERS=4
- GUNICORN_THREADS=4
- DIRTY_WORKERS=9
- DIRTY_TIMEOUT=300
- LOG_LEVEL=info
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
# Resource limits (optional)
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 256M
# Test runner service
tests:
build:
context: ../..
dockerfile: examples/celery_alternative/Dockerfile
depends_on:
app:
condition: service_healthy
environment:
- APP_URL=http://app:8000
command: ["python", "-m", "pytest", "tests/", "-v", "--tb=short"]
profiles:
- test
# For comparison, here's what a Celery deployment would look like:
#
# services:
# web:
# build: .
# command: gunicorn app:app -b 0.0.0.0:8000
# ports:
# - "8000:8000"
# depends_on:
# - redis
#
# celery_worker:
# build: .
# command: celery -A tasks worker -l info
# depends_on:
# - redis
#
# celery_beat:
# build: .
# command: celery -A tasks beat -l info
# depends_on:
# - redis
#
# redis:
# image: redis:alpine
# ports:
# - "6379:6379"