mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Database components with proper schema management FFmpeg components with process management Queue system with state management Processor components with proper handlers Utility components with shared instances Configuration components with validation Initialization sequence is now properly ordered: Config Manager initialization Path setup Database initialization FFmpeg setup Queue Manager initialization Video Processor setup Guild Components initialization Update Checker startup Queue Processing start Proper cleanup handling is in place: Component cleanup in reverse order Resource cleanup with timeouts Force cleanup for hung processes System-wide FFmpeg process cleanup Health monitoring is implemented for all components: Database connection monitoring Queue health checks Processor status tracking Component state validation
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""VideoArchiver cog for Red-DiscordBot"""
|
|
|
|
import asyncio
|
|
import logging
|
|
from typing import Optional
|
|
from redbot.core.bot import Red
|
|
|
|
from .core.base import VideoArchiver
|
|
from .core.initialization import initialize_cog, init_callback
|
|
from .core.cleanup import cleanup_resources
|
|
from .exceptions import ProcessingError
|
|
from .database import VideoArchiveDB
|
|
from .ffmpeg import FFmpegManager
|
|
from .queue import EnhancedVideoQueueManager
|
|
from .processor import VideoProcessor
|
|
from .config_manager import ConfigManager
|
|
from .update_checker import UpdateChecker
|
|
|
|
logger = logging.getLogger("VideoArchiver")
|
|
|
|
# Track initialization task
|
|
_init_task: Optional[asyncio.Task] = None
|
|
|
|
async def setup(bot: Red) -> None:
|
|
"""Load VideoArchiver with proper initialization."""
|
|
try:
|
|
# Create cog instance
|
|
cog = VideoArchiver(bot)
|
|
|
|
# Start initialization in background
|
|
global _init_task
|
|
_init_task = asyncio.create_task(initialize_cog(cog))
|
|
_init_task.add_done_callback(lambda t: init_callback(cog, t))
|
|
|
|
# Add cog to bot
|
|
await bot.add_cog(cog)
|
|
|
|
logger.info("VideoArchiver cog loaded successfully")
|
|
|
|
except Exception as e:
|
|
logger.error(f"Failed to load VideoArchiver: {str(e)}")
|
|
if _init_task and not _init_task.done():
|
|
_init_task.cancel()
|
|
raise
|
|
|
|
async def teardown(bot: Red) -> None:
|
|
"""Clean up when unloading."""
|
|
try:
|
|
# Cancel initialization if still running
|
|
if _init_task and not _init_task.done():
|
|
_init_task.cancel()
|
|
|
|
# Remove cog and clean up resources
|
|
if "VideoArchiver" in bot.cogs:
|
|
cog = bot.get_cog("VideoArchiver")
|
|
if cog:
|
|
await cleanup_resources(cog)
|
|
await bot.remove_cog("VideoArchiver")
|
|
|
|
logger.info("VideoArchiver cog unloaded successfully")
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error during teardown: {str(e)}")
|
|
raise
|
|
|
|
__all__ = [
|
|
'VideoArchiver',
|
|
'VideoArchiveDB',
|
|
'FFmpegManager',
|
|
'EnhancedVideoQueueManager',
|
|
'VideoProcessor',
|
|
'ConfigManager',
|
|
'UpdateChecker',
|
|
'ProcessingError'
|
|
]
|