3.4 KiB
Redis and Celery Troubleshooting Guide
This guide provides detailed steps to diagnose and fix issues with Redis and Celery in the LiveGraphs project.
Diagnosing Redis Connection Issues
Check if Redis is Running
# Check Redis server status
sudo systemctl status redis-server
# Try to ping Redis
redis-cli ping # Should return PONG
Test Redis Connectivity
Use our built-in test tool:
cd dashboard_project
python manage.py test_redis
If this fails, check the following:
-
Redis might not be running. Start it with:
sudo systemctl start redis-server -
Connection credentials may be incorrect. Check your environment variables:
echo $REDIS_URL echo $CELERY_BROKER_URL echo $CELERY_RESULT_BACKEND -
Redis might be binding only to a specific interface. Check
/etc/redis/redis.conf:grep "bind" /etc/redis/redis.conf -
Firewall rules might be blocking Redis. If you're connecting remotely:
sudo ufw status # Check if firewall is enabled sudo ufw allow 6379/tcp # Allow Redis port if needed
Fixing CSV Data Processing Issues
If you see the error zip() argument 2 is shorter than argument 1, it means the data format doesn't match the expected headers. We've implemented a fix that:
- Pads shorter rows with empty strings
- Uses more flexible date format parsing
- Provides better error handling
After these changes, your data should be processed correctly regardless of format variations.
Testing Celery Tasks
To verify if your Celery configuration is working:
# Start a Celery worker in one terminal
cd dashboard_project
celery -A dashboard_project worker --loglevel=info
# In another terminal, run the test task
cd dashboard_project
python manage.py test_celery
If the task isn't completing, check:
- Look for errors in the Celery worker terminal
- Verify broker URL settings match in both terminals:
echo $CELERY_BROKER_URL - Check if Redis is accessible from both terminals:
redis-cli ping
Checking Scheduled Tasks
To verify if scheduled tasks are configured correctly:
# List all scheduled tasks
cd dashboard_project
python manage.py celery inspect scheduled
Common issues with scheduled tasks:
-
Celery Beat not running: Start it with:
cd dashboard_project celery -A dashboard_project beat -
Task registered but not running: Check worker logs for any errors
-
Wrong schedule: Check the interval in settings.py and CELERY_BEAT_SCHEDULE
Data Source Configuration
If data sources aren't being processed correctly:
-
Verify active data sources exist:
cd dashboard_project python manage.py shell -c "from data_integration.models import ExternalDataSource; print(ExternalDataSource.objects.filter(is_active=True).count())" -
Create a default data source if needed:
cd dashboard_project python manage.py create_default_datasource -
Check source URLs and credentials in the admin interface or environment variables.
Manually Triggering Data Refresh
To manually trigger a data refresh for testing:
cd dashboard_project
python manage.py shell -c "from data_integration.tasks import periodic_fetch_chat_data; periodic_fetch_chat_data()"
This will execute the task directly without going through Celery, which is useful for debugging.