Files
atabackend/DOCKER_CELERY_QUICKSTART.md
Beyhan Oğur d50f14bcb1 first commit
2026-04-26 22:20:45 +03:00

332 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🐳 Docker Compose ile Celery - Hızlı Başlangıç
Bu döküman, Docker Compose ile Celery'yi hızlıca çalıştırmak için gerekli adımları içerir.
## ✅ Hazırlık
1. **Docker ve Docker Compose yüklü olmalı**
2. **Redis erişimi olmalı** (CELERY_BROKER_URL)
## 🚀 Development Ortamı
### Başlatma
```bash
# Tüm servisleri başlat (Django + Celery)
docker-compose up
# Arka planda çalıştır
docker-compose up -d
# Logları takip et
docker-compose logs -f
# Sadece Celery logları
docker-compose logs -f celery
```
### Test Etme
```bash
# 1. Contact API'yi test et
curl -X POST http://localhost:8000/api/v1/contact/create/ \
-H "Content-Type: application/json" \
-d '{
"name": "Test User",
"email": "test@example.com",
"subject": "Test Subject",
"message": "This is a test message."
}'
# 2. Celery loglarını kontrol et
docker-compose logs -f celery
# 3. Email'i MailPit'te kontrol et
open http://localhost:8025
```
### Durdurma
```bash
# Servisleri durdur
docker-compose down
# Volume'leri de sil
docker-compose down -v
```
## 🌐 Production Ortamı
### Hazırlık
```bash
# .env dosyası oluştur
cp .env.example .env
# .env dosyasını düzenle
nano .env
# Gerekli değerler:
# - SECRET_KEY
# - DJANGO_ALLOWED_HOSTS
# - CELERY_BROKER_URL
# - POSTGRES_* (database ayarları)
```
### Başlatma
```bash
# Tüm servisleri başlat (Django + Celery + Nginx)
docker-compose -f docker-compose.prod.yml up -d
# Build ile başlat
docker-compose -f docker-compose.prod.yml up --build -d
# Logları kontrol et
docker-compose -f docker-compose.prod.yml logs -f
# Celery logları
docker-compose -f docker-compose.prod.yml logs -f celery-atahan
```
### Servis Durumları
```bash
# Container durumlarını kontrol et
docker-compose -f docker-compose.prod.yml ps
# Kaynak kullanımı
docker stats
```
### Durdurma
```bash
# Servisleri durdur
docker-compose -f docker-compose.prod.yml down
# Yeniden başlat
docker-compose -f docker-compose.prod.yml restart
# Sadece Celery'yi yeniden başlat
docker-compose -f docker-compose.prod.yml restart celery-atahan
```
## 🔧 Yararlı Komutlar
### Migrations
```bash
# Development
docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate
# Production
docker-compose -f docker-compose.prod.yml exec web-atahan python manage.py migrate
```
### Django Shell
```bash
# Development
docker-compose exec web python manage.py shell
# Production
docker-compose -f docker-compose.prod.yml exec web-atahan python manage.py shell
```
### Celery Container'a Bağlanma
```bash
# Development
docker-compose exec celery bash
# Production
docker-compose -f docker-compose.prod.yml exec celery-atahan bash
```
### Task Sonuçlarını Görme
```bash
# Shell aç
docker-compose exec web python manage.py shell
# Shell içinde:
from django_celery_results.models import TaskResult
TaskResult.objects.all()
TaskResult.objects.filter(status='SUCCESS')
TaskResult.objects.order_by('-date_done')[:10]
```
## 📊 İzleme
### Container Logları
```bash
# Tüm servisler (Development)
docker-compose logs -f
# Tüm servisler (Production)
docker-compose -f docker-compose.prod.yml logs -f
# Son 100 satır
docker-compose logs --tail=100 celery
# Belirli zaman aralığı
docker-compose logs --since 2026-01-15T10:00:00 celery
```
### Celery İstatistikleri
```bash
# Aktif task'lar
docker-compose exec celery celery -A core inspect active
# Worker istatistikleri
docker-compose exec celery celery -A core inspect stats
# Kayıtlı task'lar
docker-compose exec celery celery -A core inspect registered
```
### Django Admin
1. **Admin panele gir:**
- Development: http://localhost:8000/admin/
- Production: http://your-domain.com/admin/
2. **Task sonuçlarını gör:**
- Django Celery Results → Task results
3. **Periyodik task'ları yönet:**
- Django Celery Beat → Periodic tasks
## 🐛 Sorun Giderme
### Celery Çalışmıyor
```bash
# 1. Logları kontrol et
docker-compose logs celery
# 2. Container durumunu kontrol et
docker-compose ps
# 3. Container'ı yeniden başlat
docker-compose restart celery
# 4. Rebuild et
docker-compose up --build celery
```
### Email Gönderilmiyor
```bash
# 1. Celery loglarını kontrol et
docker-compose logs -f celery
# 2. MailPit çalışıyor mu? (Development)
open http://localhost:8025
# 3. Email ayarlarını kontrol et
docker-compose exec web python manage.py shell
>>> from django.conf import settings
>>> print(settings.EMAIL_BACKEND)
>>> print(settings.EMAIL_HOST)
```
### Redis Bağlantı Hatası
```bash
# Environment variable'ları kontrol et
docker-compose exec celery env | grep CELERY
# Redis bağlantısını test et
docker-compose exec celery python -c "
from django.conf import settings
print(settings.CELERY_BROKER_URL)
"
```
## 📚 Servis Portları
### Development
- **Django**: http://localhost:8000
- **MailPit UI**: http://localhost:8025
- **MailPit SMTP**: localhost:1025
### Production
- **Nginx**: http://localhost:8077
- **Django (Direct)**: http://localhost:8800
## 🔐 Environment Variables
### Development (.env veya docker-compose.yml)
```bash
DEBUG=1
CELERY_BROKER_URL=redis://default:password@host:6379/5
CELERY_RESULT_BACKEND=django-db
POSTGRES_DB=server_dj
POSTGRES_USER=server_dj
POSTGRES_PASSWORD=1234
POSTGRES_HOST=10.80.80.50
POSTGRES_PORT=5432
```
### Production (.env)
```bash
DEBUG=0
SECRET_KEY=your-secret-key-here
DJANGO_ALLOWED_HOSTS=yourdomain.com
CELERY_BROKER_URL=redis://default:password@host:6379/5
CELERY_RESULT_BACKEND=django-db
POSTGRES_DB=your-db
POSTGRES_USER=your-user
POSTGRES_PASSWORD=your-password
POSTGRES_HOST=your-host
POSTGRES_PORT=5432
```
## 📖 Detaylı Dökümanlar
- **DOCKER_CELERY.md** - Celery kullanımı hakkında detaylı bilgi
- **DOCKER_README.md** - Docker genel kullanımı
- **CONTACT_EMAIL_SETUP.md** - Contact email kurulumu
## 🎯 Önemli Notlar
1.**Celery worker ve beat** aynı container'da çalışır
2.**Redis** harici olarak çalışmalı (CELERY_BROKER_URL)
3.**PostgreSQL** harici olarak çalışmalı
4.**MailPit** development için email testleri sağlar
5. ✅ Production'da gerçek SMTP kullanın
## 🚨 İlk Başlatmada Yapılacaklar
```bash
# 1. Servisleri başlat
docker-compose up -d
# 2. Migration'ları uygula
docker-compose exec web python manage.py migrate
# 3. Superuser oluştur
docker-compose exec web python manage.py createsuperuser
# 4. Static dosyaları topla (Production)
docker-compose exec web python manage.py collectstatic --noinput
# 5. Test et
curl -X POST http://localhost:8000/api/v1/contact/create/ \
-H "Content-Type: application/json" \
-d '{"name":"Test","email":"test@test.com","subject":"Test","message":"Test"}'
# 6. Logları kontrol et
docker-compose logs -f celery
```
---
**Yardım**: Sorun yaşarsanız `DOCKER_CELERY.md` dosyasına bakın veya logları kontrol edin.