import asyncio
import logging

from job_handlers import (
    asr_handler,
    completion_handler,
    compress_handler,
    convert_handler,
    ocr_handler,
    pro_completion_handler,
    tts_handler,
    web_search_handler,
)
from job_system import RedisJobManager, RedisWorker

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s - %(message)s",
)
logger = logging.getLogger("worker")


async def main() -> None:
    manager = RedisJobManager()
    manager.register_handler("completion", completion_handler)
    manager.register_handler("pro_completion", pro_completion_handler)
    manager.register_handler("web_search", web_search_handler)
    manager.register_handler("compress", compress_handler)
    manager.register_handler("ocr", ocr_handler)
    manager.register_handler("convert", convert_handler)
    manager.register_handler("tts", tts_handler)
    manager.register_handler("asr", asr_handler)
    worker = RedisWorker(manager)
    try:
        await worker.run_forever()
    finally:
        await manager.close()


if __name__ == "__main__":
    asyncio.run(main())
