Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ A Django RESTful API for managing personal or team tasks — featuring PostgreSQ

- ✅ Django 5 + Django REST Framework
- ✅ PostgreSQL database (via Docker)
- ✅ RabbitMQ for background tasks (Celery-ready)
- ✅ RabbitMQ for background tasks (Celery integrated)
- ✅ Asynchronous task logging using Celery
- ✅ Environment config with `.env` and `python-decouple`
- ✅ Swagger UI for API documentation
- ✅ Containerized with Docker
Expand All @@ -21,12 +22,13 @@ A Django RESTful API for managing personal or team tasks — featuring PostgreSQ

```
taskflow-api/
├── taskflow_api/ # Django project
├── tasks/ # App: task models, views, serializers
├── taskflow_api/ # Django project (includes celery.py)
├── tasks/ # App: task models, views, serializers, signals, celery tasks
├── requirements.txt # Python dependencies
├── Dockerfile # Production image for gunicorn
├── docker-compose.yml # DB and RabbitMQ container setup
├── .env # Environment configuration
├── logs/ # Directory for activity logs (auto-created)
├── run_server.sh # Run production server (Gunicorn)
└── start-dev-services.sh # Run DB + RabbitMQ for development
```
Expand Down Expand Up @@ -79,20 +81,38 @@ Use this when you want to run Django locally (`runserver`) and containers only f

> This will:
> - Start PostgreSQL and RabbitMQ containers
> - Stop and remove any running `web` container
> - Stop and remove any running web container
> - Run DB migrations automatically

### ▶️ Then Run Django:
```bash
python3 manage.py runserver
```

### ▶️ Run Celery Worker:
```bash
celery -A taskflow_api worker --loglevel=info
```

Open:
- Swagger docs: http://localhost:8000/docs/
- API root: http://localhost:8000/api/tasks/

---

## 🧩 Celery Logging Task

When a task is created through the API, a Celery worker will automatically:

- Run `log_task_action` in the background using `celery -A taskflow_api worker --loglevel=info`
- Write an entry like this to `logs/task_activity.log`:

```
[2025-09-14 19:45:00] Task #12 ('Example Task') was created via Celery background task.
```

---

## 🏭 Production Mode (Dockerized Web)

### ▶️ Build & Run All Services:
Expand All @@ -117,11 +137,12 @@ docker compose up --build
- **Backend**: Django 5, DRF
- **Database**: PostgreSQL (Docker)
- **Broker**: RabbitMQ (Docker)
- **Background Jobs**: Celery (activity logging)
- **Containerization**: Docker, Docker Compose
- **CI-ready**: Gunicorn + environment-based config

---

## 📜 License

MIT © Omid Hashemzadeh
MIT © Omid Hashemzadeh
22 changes: 20 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ services:
env_file:
- .env
environment:
# Useful if override needed, else .env handles it
POSTGRES_HOST: db
CELERY_BROKER_URL: amqp://guest:guest@rabbitmq:5672//


db:
image: postgres
Expand All @@ -25,5 +28,20 @@ services:
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
- "5672:5672" # AMQP (used by Celery)
- "15672:15672" # RabbitMQ management UI

celery:
build: .
command: celery -A taskflow_api worker --loglevel=info
volumes:
- .:/app
depends_on:
- db
- rabbitmq
env_file:
- .env
environment:
# Useful if override needed, else .env handles it
POSTGRES_HOST: db
CELERY_BROKER_URL: amqp://guest:guest@rabbitmq:5672//
11 changes: 11 additions & 0 deletions lint-clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo "🔍 Linting and fixing with Ruff (ignoring migrations)..."

# Lint and auto-fix, ignoring migration files
ruff check --fix . --exclude migrations

# Format code (also ignores excluded by default)
ruff format . --exclude migrations

echo "✅ Code linted and formatted!"
2 changes: 1 addition & 1 deletion tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def log_task_action(task_id, action):
"""Log task ID and title to a file."""
try:
task = Task.objects.get(id=task_id)
log_line = f"[{now()}] Logging Celery Task : Task #{task.id} ('{task.title}') was {action} using celery.\n"
log_line = f"[{now()}] Task #{task.id} ('{task.title}') was {action} via Celery background task.\n"
except Task.DoesNotExist:
log_line = f"[{now()}] ERROR: Task {task_id} not found for action '{action}'\n"

Expand Down