Files
yottob/celery_app.py
Ryan Chen be76f0a610 Add comprehensive deletion functionality and scheduled cleanup
Features:
- Delete entire channels with all videos and downloaded files
- Delete individual video files while keeping database entries
- Scheduled automatic cleanup of videos older than 7 days
- Proper cascading deletes with file cleanup

Channel Deletion:
- New DELETE endpoint at /api/channels/<id>
- Removes channel, all video entries, and downloaded files
- User ownership verification
- Returns count of deleted files
- UI button on channels page with detailed confirmation dialog

Video File Deletion:
- New DELETE endpoint at /api/videos/<id>/file
- Celery async task to remove file from disk
- Resets download status to pending (allows re-download)
- UI button on watch page for completed videos
- Confirmation dialog with clear warnings

Scheduled Cleanup:
- Celery beat configuration for periodic tasks
- cleanup_old_videos task runs daily at midnight
- Automatically deletes videos completed more than 7 days ago
- Removes files and resets database status
- scheduled_tasks.py for beat schedule configuration
- verify_schedule.py helper to check task scheduling

UI Improvements:
- Added .btn-danger CSS class (black/white theme)
- Delete buttons with loading states
- Detailed confirmation dialogs warning about permanent deletion
- Dashboard now filters to show only completed videos

Bug Fixes:
- Fixed navbar alignment issues
- Added proper error handling for file deletion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:55:43 -05:00

48 lines
1.4 KiB
Python

"""Celery application configuration."""
import os
from celery import Celery
# Get configuration from environment variables
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0")
# Configure Celery
celery_app = Celery(
"yottob",
broker=CELERY_BROKER_URL,
backend=CELERY_RESULT_BACKEND,
include=["download_service", "scheduled_tasks"]
)
# Celery configuration
celery_app.conf.update(
task_serializer="json",
accept_content=["json"],
result_serializer="json",
timezone="UTC",
enable_utc=True,
task_track_started=True,
task_time_limit=3600, # 1 hour max per task
task_soft_time_limit=3300, # 55 minutes soft limit
worker_prefetch_multiplier=1, # Process one task at a time
worker_max_tasks_per_child=50, # Restart worker after 50 tasks
beat_schedule={
"cleanup-old-videos-daily": {
"task": "download_service.cleanup_old_videos",
"schedule": 86400.0, # Run every 24 hours (in seconds)
},
},
)
# Scheduled tasks
from celery.schedules import crontab
celery_app.conf.beat_schedule = {
"check-latest-videos-midnight": {
"task": "scheduled_tasks.check_and_download_latest_videos",
"schedule": crontab(minute=0, hour=0), # Run at midnight UTC
},
}