Created a new constants.py file to store the REACTIONS dictionary

Updated all files to import REACTIONS from constants.py instead of reactions.py:
queue_processor.py
message_handler.py
reactions.py (now only contains reaction handling functions)
events.py (now imports REACTIONS from constants.py and handle_archived_reaction from reactions.py)
core.py
queue_handler.py
processor/init.py
This commit is contained in:
pacnpal
2024-11-16 18:12:35 +00:00
parent 8fe8ba0766
commit dd467df5fc
8 changed files with 45 additions and 25 deletions

View File

@@ -1,40 +1,45 @@
"""Video processing module for VideoArchiver"""
from .core import VideoProcessor
from .reactions import REACTIONS
from .constants import REACTIONS
from .progress_tracker import ProgressTracker
from .message_handler import MessageHandler
from .queue_handler import QueueHandler
# Export public classes and constants
__all__ = [
'VideoProcessor',
'REACTIONS',
'ProgressTracker',
'MessageHandler',
'QueueHandler'
"VideoProcessor",
"REACTIONS",
"ProgressTracker",
"MessageHandler",
"QueueHandler",
]
# Create a shared progress tracker instance for module-level access
progress_tracker = ProgressTracker()
# Export progress tracking functions that wrap the instance methods
def update_download_progress(url, progress_data):
"""Update download progress for a specific URL"""
progress_tracker.update_download_progress(url, progress_data)
def complete_download(url):
"""Mark a download as complete"""
progress_tracker.complete_download(url)
def increment_download_retries(url):
"""Increment retry count for a download"""
progress_tracker.increment_download_retries(url)
def get_download_progress(url=None):
"""Get download progress for a specific URL or all downloads"""
return progress_tracker.get_download_progress(url)
def get_active_operations():
"""Get all active operations"""
return progress_tracker.get_active_operations()

View File

@@ -0,0 +1,13 @@
"""Constants for VideoProcessor"""
# Reaction emojis
REACTIONS = {
'queued': '📹',
'processing': '⚙️',
'success': '',
'error': '',
'archived': '🔄', # New reaction for already archived videos
'numbers': ['1', '2', '3', '4', '5'],
'progress': ['', '🟨', '🟩'],
'download': ['0', '2', '4', '6', '8', '🔟']
}

View File

@@ -3,7 +3,7 @@
import logging
import asyncio
from enum import Enum
from typing import Optional, Tuple, Dict, Any
from typing import Optional, Tuple, Dict, Any, List
from datetime import datetime
import discord
from discord.ext import commands
@@ -13,7 +13,7 @@ from .queue_handler import QueueHandler
from .progress_tracker import ProgressTracker
from .status_display import StatusDisplay
from .cleanup_manager import CleanupManager
from .reactions import REACTIONS
from .constants import REACTIONS
logger = logging.getLogger("VideoArchiver")

View File

@@ -10,7 +10,7 @@ import discord
from .url_extractor import URLExtractor
from .message_validator import MessageValidator
from .queue_processor import QueueProcessor
from .reactions import REACTIONS
from .constants import REACTIONS
logger = logging.getLogger("VideoArchiver")

View File

@@ -7,7 +7,7 @@ import discord
from typing import Dict, Optional, Tuple, Any
from datetime import datetime
from .reactions import REACTIONS
from .constants import REACTIONS
from .progress_tracker import ProgressTracker
logger = logging.getLogger("VideoArchiver")
@@ -305,3 +305,14 @@ class QueueHandler:
except Exception as e:
logger.error(f"Failed to update download progress reaction: {e}")
def is_healthy(self) -> bool:
"""Check if handler is healthy"""
# Check if any downloads are stuck
current_time = datetime.utcnow()
for url, task in self._active_downloads.items():
if not task.done() and task.get_coro().cr_frame.f_locals.get('start_time'):
start_time = task.get_coro().cr_frame.f_locals['start_time']
if (current_time - start_time).total_seconds() > 3600: # 1 hour timeout
return False
return True

View File

@@ -8,7 +8,7 @@ from datetime import datetime
import discord
from ..queue.models import QueueItem
from .reactions import REACTIONS
from .constants import REACTIONS
logger = logging.getLogger("VideoArchiver")

View File

@@ -1,22 +1,12 @@
"""Reaction emojis and reaction management for VideoProcessor"""
"""Reaction handling for VideoProcessor"""
import logging
import asyncio
import discord
logger = logging.getLogger("VideoArchiver")
from .constants import REACTIONS
# Reaction emojis
REACTIONS = {
'queued': '📹',
'processing': '⚙️',
'success': '',
'error': '',
'archived': '🔄', # New reaction for already archived videos
'numbers': ['1', '2', '3', '4', '5'],
'progress': ['', '🟨', '🟩'],
'download': ['0', '2', '4', '6', '8', '🔟']
}
logger = logging.getLogger("VideoArchiver")
async def handle_archived_reaction(message: discord.Message, user: discord.User, db) -> None:
"""Handle reaction to archived video message"""