A minimal project demonstrating how to use FastAPI, RQ (Redis Queue), and Docker for background job processing.
src/app.py- FastAPI application with an endpoint to enqueue jobs.src/tasks.py- Background task(s) for RQ.src/worker.py- RQ worker process.src/main.py- Main FastAPI application (with all endpoints).src/utils.py- Utility functions for queue/job management.tests/simulate_client.py- Rich-powered script to test the API and poll job status.docker-compose.yml- Orchestrates FastAPI, Redis, RQ worker, and rq-dashboard..env- Environment variables for configuration.
docker-compose up --build- FastAPI app: http://localhost:8000
- RQ Dashboard: http://localhost:9181
You can use the provided test script (with rich UI):
python tests/simulate_client.pyOr manually with curl (example for addition):
curl -X POST "http://localhost:8000/tasks/enqueue" \
-H "Content-Type: application/json" \
-d '{"a": 2, "b": 3, "operation": "add"}'You can poll the job status using the API:
curl http://localhost:8000/tasks/job/<job_id>Or visit http://localhost:9181 to view jobs and results in the dashboard.
- Add more tasks to
src/tasks.py. - Add more endpoints to
src/main.py.
To stop and remove containers:
docker-compose down -v