Skip to main content

Celery Quick Start Guide

Fast setup guide for running Celery workers and beat scheduler locally and in production.

Local Development - 3 Commands

1. Start Redis

docker run -d -p 6379:6379 redis:7-alpine

2. Start Celery Worker

celery -A license_platform worker --loglevel=info

3. Start Celery Beat (Scheduler)

celery -A license_platform beat --loglevel=info

Test Task Execution

Django Shell

python manage.py shell

from licenses.tasks import cleanup_zombie_sessions

# Execute task asynchronously
task = cleanup_zombie_sessions.delay()

# Check status
print(task.id)
print(task.status)

# Get result (blocks until complete)
result = task.get(timeout=10)
print(result)
# {'sessions_found': 5, 'sessions_cleaned': 5, 'errors': 0, 'duration_seconds': 0.45}

Kubernetes Deployment - 2 Commands

Deploy Workers + Beat

kubectl apply -f k8s/celery-worker-deployment.yaml
kubectl apply -f k8s/celery-beat-deployment.yaml

Verify Deployment

kubectl get pods -n coditect-license-platform | grep celery

Expected output:

celery-worker-abc123-xyz   1/1   Running   0   10s
celery-worker-def456-uvw 1/1 Running 0 10s
celery-beat-ghi789-rst 1/1 Running 0 10s

Monitor Tasks

View Logs

# Worker logs
kubectl logs -f deployment/celery-worker -n coditect-license-platform

# Beat logs
kubectl logs -f deployment/celery-beat -n coditect-license-platform

Check Worker Status

celery -A license_platform inspect active
celery -A license_platform inspect stats

Troubleshooting

Workers not processing tasks?

# Check Redis connection
redis-cli ping # Should return PONG

# Restart workers
kubectl rollout restart deployment/celery-worker -n coditect-license-platform

Beat not scheduling tasks?

# Check beat logs
kubectl logs deployment/celery-beat -n coditect-license-platform

# Verify beat is running
ps aux | grep "celery.*beat"

Available Tasks

TaskSchedulePurpose
cleanup_zombie_sessionsHourlyClean up expired sessions
check_license_expirationsDailySend expiration notifications
aggregate_usage_metricsTBDProcess analytics data

Complete Documentation

See celery-integration.md for comprehensive documentation.