Skip to content

AminMosallanejad339/Celery_Flask_Pro

Repository files navigation

📄 README.md

Celery + Flask + Redis Example Project

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.


Project Screenshot

Celery Flask Project: Auto Email Response

![Celery Auto-Reply](images/Screenshot 2025-08-19 025643.png)

🔧 Requirements

  • Python 3.8+
  • Redis server running locally
  • Install dependencies:
pip install -r requirements.txt

```bash
pip install -r requirements.txt

Running the Project

1. Start Redis

Make sure Redis server is running:

redis-server

Check if Redis is working:

redis-cli ping

It should return:

PONG

2. Start Celery Worker

Open a new terminal and run:

celery -A tasks.celery_app worker --loglevel=info

This starts the Celery worker that listens for tasks.


3. Start Flask App

In another terminal:

python3 app.py

Flask will run on http://127.0.0.1:5000


📬 Usage

1. Send an Email Task

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"
}

2. Check Task Status

curl http://127.0.0.1:5000/status/a4d9b5d7-2d1f-4f4b-9b1f-9e8f5c2d6a22

Example response:

{
  "state": "SUCCESS",
  "result": "Email to amin.mosallanejad.academic@proton.me sent successfully!"
}

✅ Features

  • Background task execution with Celery
  • Redis as message broker & result backend
  • REST API built with Flask
  • Task status tracking

Notes

  • This project simulates email sending with time.sleep(5).
  • You can integrate real email sending (e.g., using smtplib or Flask-Mail) inside send_email function in tasks.py.
  • Scale workers by running multiple Celery worker instances.

About

Automate email responses using Celery, Redis, and Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages