feat: Add Docker entrypoint script for application orchestration and implement cleanup for stuck photo processing tasks with improved error handling.
This commit is contained in:
65
cleanup_commands.txt
Normal file
65
cleanup_commands.txt
Normal file
@@ -0,0 +1,65 @@
|
||||
# Cleanup Commands for Stuck Celery Tasks
|
||||
|
||||
## Quick Commands
|
||||
|
||||
### 1. Restart Celery Worker (to apply code changes)
|
||||
```bash
|
||||
docker restart mix_celery_worker
|
||||
docker logs -f --tail 50 mix_celery_worker
|
||||
```
|
||||
|
||||
### 2. Run Cleanup Script (Interactive)
|
||||
```bash
|
||||
# Copy script to container
|
||||
docker cp cleanup_stuck_photos.py mix_web:/app/
|
||||
|
||||
# Run interactively
|
||||
docker exec -it mix_web python manage.py shell
|
||||
>>> exec(open('cleanup_stuck_photos.py').read())
|
||||
```
|
||||
|
||||
### 3. Manual Cleanup (Django Shell)
|
||||
```bash
|
||||
docker exec -it mix_web python manage.py shell
|
||||
```
|
||||
|
||||
Then run:
|
||||
```python
|
||||
from django.db import connection
|
||||
from products.models import ProductPhoto, PhotoProcessingStatus
|
||||
from django.core.files.storage import default_storage
|
||||
|
||||
# Activate schema
|
||||
connection.set_schema('mixflowers')
|
||||
|
||||
# Find photo #6
|
||||
photo = ProductPhoto.objects.get(id=6)
|
||||
print(f"Photo: {photo}")
|
||||
print(f"File path: {photo.image.name}")
|
||||
print(f"File exists: {default_storage.exists(photo.image.name)}")
|
||||
|
||||
# Option 1: Delete the record
|
||||
photo.delete()
|
||||
|
||||
# Option 2: Clear the image field (keep record)
|
||||
# photo.image = None
|
||||
# photo.save()
|
||||
|
||||
# Clean up stuck processing statuses
|
||||
stuck = PhotoProcessingStatus.objects.filter(status__in=['pending', 'processing'])
|
||||
print(f"Found {stuck.count()} stuck statuses")
|
||||
stuck.update(status='failed', error_message='File was deleted before processing')
|
||||
```
|
||||
|
||||
## What Was Fixed
|
||||
|
||||
1. **FileNotFoundError handling**: Task now fails immediately instead of retrying when file is missing
|
||||
2. **File existence check**: Added check before processing to catch missing files early
|
||||
3. **Status updates**: PhotoProcessingStatus is properly updated to 'failed' when file not found
|
||||
|
||||
## Testing
|
||||
|
||||
After restarting Celery worker:
|
||||
1. Upload a new photo - should process normally
|
||||
2. Check logs - should not see retry loops for missing files
|
||||
3. Verify stuck tasks are cleaned up
|
||||
Reference in New Issue
Block a user