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

@@ -7,7 +7,8 @@ import traceback
from typing import TYPE_CHECKING, Dict, Any, Optional from typing import TYPE_CHECKING, Dict, Any, Optional
from datetime import datetime from datetime import datetime
from ..processor.reactions import REACTIONS, handle_archived_reaction from ..processor.constants import REACTIONS
from ..processor.reactions import handle_archived_reaction
from .guild import initialize_guild_components, cleanup_guild_components from .guild import initialize_guild_components, cleanup_guild_components
from .error_handler import error_manager from .error_handler import error_manager
from .response_handler import response_manager from .response_handler import response_manager

View File

@@ -1,40 +1,45 @@
"""Video processing module for VideoArchiver""" """Video processing module for VideoArchiver"""
from .core import VideoProcessor from .core import VideoProcessor
from .reactions import REACTIONS from .constants import REACTIONS
from .progress_tracker import ProgressTracker from .progress_tracker import ProgressTracker
from .message_handler import MessageHandler from .message_handler import MessageHandler
from .queue_handler import QueueHandler from .queue_handler import QueueHandler
# Export public classes and constants # Export public classes and constants
__all__ = [ __all__ = [
'VideoProcessor', "VideoProcessor",
'REACTIONS', "REACTIONS",
'ProgressTracker', "ProgressTracker",
'MessageHandler', "MessageHandler",
'QueueHandler' "QueueHandler",
] ]
# Create a shared progress tracker instance for module-level access # Create a shared progress tracker instance for module-level access
progress_tracker = ProgressTracker() progress_tracker = ProgressTracker()
# Export progress tracking functions that wrap the instance methods # Export progress tracking functions that wrap the instance methods
def update_download_progress(url, progress_data): def update_download_progress(url, progress_data):
"""Update download progress for a specific URL""" """Update download progress for a specific URL"""
progress_tracker.update_download_progress(url, progress_data) progress_tracker.update_download_progress(url, progress_data)
def complete_download(url): def complete_download(url):
"""Mark a download as complete""" """Mark a download as complete"""
progress_tracker.complete_download(url) progress_tracker.complete_download(url)
def increment_download_retries(url): def increment_download_retries(url):
"""Increment retry count for a download""" """Increment retry count for a download"""
progress_tracker.increment_download_retries(url) progress_tracker.increment_download_retries(url)
def get_download_progress(url=None): def get_download_progress(url=None):
"""Get download progress for a specific URL or all downloads""" """Get download progress for a specific URL or all downloads"""
return progress_tracker.get_download_progress(url) return progress_tracker.get_download_progress(url)
def get_active_operations(): def get_active_operations():
"""Get all active operations""" """Get all active operations"""
return progress_tracker.get_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 logging
import asyncio import asyncio
from enum import Enum from enum import Enum
from typing import Optional, Tuple, Dict, Any from typing import Optional, Tuple, Dict, Any, List
from datetime import datetime from datetime import datetime
import discord import discord
from discord.ext import commands from discord.ext import commands
@@ -13,7 +13,7 @@ from .queue_handler import QueueHandler
from .progress_tracker import ProgressTracker from .progress_tracker import ProgressTracker
from .status_display import StatusDisplay from .status_display import StatusDisplay
from .cleanup_manager import CleanupManager from .cleanup_manager import CleanupManager
from .reactions import REACTIONS from .constants import REACTIONS
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")

View File

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

View File

@@ -7,7 +7,7 @@ import discord
from typing import Dict, Optional, Tuple, Any from typing import Dict, Optional, Tuple, Any
from datetime import datetime from datetime import datetime
from .reactions import REACTIONS from .constants import REACTIONS
from .progress_tracker import ProgressTracker from .progress_tracker import ProgressTracker
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -305,3 +305,14 @@ class QueueHandler:
except Exception as e: except Exception as e:
logger.error(f"Failed to update download progress reaction: {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 import discord
from ..queue.models import QueueItem from ..queue.models import QueueItem
from .reactions import REACTIONS from .constants import REACTIONS
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")

View File

@@ -1,22 +1,12 @@
"""Reaction emojis and reaction management for VideoProcessor""" """Reaction handling for VideoProcessor"""
import logging import logging
import asyncio import asyncio
import discord import discord
logger = logging.getLogger("VideoArchiver") from .constants import REACTIONS
# Reaction emojis logger = logging.getLogger("VideoArchiver")
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', '🔟']
}
async def handle_archived_reaction(message: discord.Message, user: discord.User, db) -> None: async def handle_archived_reaction(message: discord.Message, user: discord.User, db) -> None:
"""Handle reaction to archived video message""" """Handle reaction to archived video message"""