This project demonstrates how to use Celery with Flask and Redis to run background tasks asynchronously.
The example simulates sending an email (in the background) while the API responds immediately.

- Python 3.8+
- Redis server running locally
- Install dependencies:
pip install -r requirements.txt
```bash
pip install -r requirements.txtMake sure Redis server is running:
redis-serverCheck if Redis is working:
redis-cli pingIt should return:
PONG
Open a new terminal and run:
celery -A tasks.celery_app worker --loglevel=infoThis starts the Celery worker that listens for tasks.
In another terminal:
python3 app.pyFlask will run on http://127.0.0.1:5000
Use curl or Postman to send a request:
curl -X POST http://127.0.0.1:5000/send-email \
-H "Content-Type: application/json" \
-d '{"to":"amin.mosallanejad.academic@proton.me", "subject":"Welcome", "body":"Thanks for registering!"}'Example response:
{
"message": "Task submitted!",
"task_id": "a4d9b5d7-2d1f-4f4b-9b1f-9e8f5c2d6a22"
}curl http://127.0.0.1:5000/status/a4d9b5d7-2d1f-4f4b-9b1f-9e8f5c2d6a22Example response:
{
"state": "SUCCESS",
"result": "Email to amin.mosallanejad.academic@proton.me sent successfully!"
}- Background task execution with Celery
- Redis as message broker & result backend
- REST API built with Flask
- Task status tracking
- This project simulates email sending with
time.sleep(5). - You can integrate real email sending (e.g., using smtplib or Flask-Mail) inside
send_emailfunction intasks.py. - Scale workers by running multiple Celery worker instances.