A minimal FastAPI service demonstrating background job processing with Redis Queue (RQ): submit a job over HTTP, track its status, and fetch the result once it finishes.
POST /job— enqueues a background job (prints numbers in a range) and returns a job IDGET /job/{job_id}— polls job status and resultGET /health— reports API and Redis connection status- A separate RQ worker process consuming the same queue
- Fully containerized: API, Redis, and worker as separate services
- FastAPI, Python 3.13
- Redis + RQ (Redis Queue)
- Pydantic v2
- Docker Compose
git clone git@github.com:mortogo321/python-fastapi-redis-queue.git
cd python-fastapi-redis-queue
docker compose -f docker/docker-compose.development.yaml up -d --buildStarts three services: api (port 8000), redis (port 6379), and worker.
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Stop:
docker compose -f docker/docker-compose.development.yaml down --rmi all --remove-orphanspip install -r requirements.txt
redis-server
uvicorn main:app --reload --port 8000
rq worker task_queue # in a separate terminalcurl -X POST http://localhost:8000/job \
-H "Content-Type: application/json" \
-d '{"lowest": 1, "highest": 100}'
# => {"job_id": "...", "status": "queued", ...}
curl http://localhost:8000/job/<job_id>
# => {"status": "finished", "result": {...}, ...}main.py # FastAPI app and endpoints
job.py # Background job function run by the worker
requirements.txt
docker/
├── Dockerfile
└── docker-compose.development.yaml
Configuration is read from environment variables (REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, QUEUE_NAME) — see .env.development. That file holds a dev-only Redis password for local compose; override REDIS_PASSWORD in the environment for anything beyond local development.
pip install -r requirements-dev.txt
ruff check . && ruff format --check .
pytest