A production-ready distributed task queue system built with FastAPI, Redis, and RQ. Submit async jobs, track their progress, and scale workers independently.
- ✅ Async Task Processing - Submit tasks to queue, execute asynchronously
- ✅ Real-time Status Tracking - Monitor task progress via REST API
- ✅ Multiple Task Types - Email, image processing, data export examples
- ✅ Worker Management - Scale workers independently from API
- ✅ Redis Integration - Persistent job queue with RQ
- ✅ React Dashboard - Submit tasks and monitor status
- ✅ Docker & Docker Compose - Easy local setup
- Backend: FastAPI, Redis, RQ
- Frontend: React, Axios, Vite
- Infrastructure: Docker, Docker Compose
- Docker & Docker Compose (OR Python 3.11+, Redis, Node 18+)
docker-compose upThis starts:
- Redis on port 6379
- API on http://localhost:8000
- Worker processes jobs continuously
- Docs on http://localhost:8000/docs
Backend:
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reloadWorker (separate terminal):
cd backend
python worker.pyFrontend:
cd frontend
npm install
npm run devVisit: http://localhost:3000
The application provides an intuitive React-based dashboard for submitting tasks and monitoring their status:
Features shown:
- Task Selector - Choose from available task types (send_email, process_image, export_data)
- Arguments Editor - Input JSON arguments for selected task
- Submit Button - Queue the task for processing
- Active Tasks List - Real-time view of queued and processing tasks
- Status Tracking - Monitor task progress and results
POST /tasks
Content-Type: application/json
{
"task_name": "send_email",
"arguments": {
"recipient": "user@example.com",
"subject": "Hello"
}
}
Response: { "task_id": "abc123", "status": "queued", "task_name": "send_email" }GET /tasks/{task_id}
Response: {
"task_id": "abc123",
"status": "finished",
"result": "Email sent to user@example.com: Hello",
"error": null
}GET /tasks
Response: {
"total": 5,
"tasks": [
{ "task_id": "abc123", "status": "finished", "task_name": "send_email" },
...
]
}GET /stats
Response: {
"queued": 2,
"finished": 10,
"failed": 1,
"total_jobs": 13
}-
send_email - Send email notification
{ "recipient": "user@example.com", "subject": "Subject Line" } -
process_image - Process image file
{ "image_path": "/path/to/image.jpg", "operation": "resize" } -
export_data - Export data to format
{ "format": "csv", "count": 1000 }
distributed-task-queue-app/
├── backend/
│ ├── main.py # FastAPI app & task API
│ ├── worker.py # RQ worker process
│ ├── requirements.txt # Python dependencies
│ └── Dockerfile
├── frontend/
│ ├── src/
│ │ ├── App.jsx # React dashboard
│ │ ├── App.css
│ │ └── main.jsx
│ ├── package.json
│ ├── vite.config.js
│ └── index.html
├── docker-compose.yml
└── README.md
- Queued - Task submitted, waiting for worker
- Started - Worker processing the task
- Finished - Task completed successfully
- Failed - Task execution failed
Add more workers to process jobs faster:
docker-compose up -d --scale worker=3Submit a test task:
curl -X POST http://localhost:8000/tasks \
-H "Content-Type: application/json" \
-d '{"task_name": "send_email", "arguments": {"recipient": "test@example.com", "subject": "Test"}}'Check status:
curl http://localhost:8000/tasks/{task_id}Redis connection error?
- Ensure Redis is running:
docker ps | grep redis - Check REDIS_HOST and REDIS_PORT in .env
Task stuck in 'queued'?
- Worker process may have crashed
- Restart worker:
python worker.py
- Database persistence (PostgreSQL)
- Task retries & dead letter queue
- Email notifications
- Admin dashboard
- Authentication & authorization
MIT
