"""Daemon worker: periodic channel scan + video processing.""" from __future__ import annotations import logging import time from core.youtube import scan_all_channels from core.pipeline import process_pending logger = logging.getLogger(__name__) def run_once() -> None: """Single daemon cycle: scan channels then process pending videos.""" logger.info("=== Daemon cycle start ===") try: new_count = scan_all_channels() logger.info("Scan complete: %d new videos", new_count) except Exception as e: logger.error("Channel scan failed: %s", e) try: rest_count = process_pending(limit=10) logger.info("Processing complete: %d restaurants extracted", rest_count) except Exception as e: logger.error("Video processing failed: %s", e) logger.info("=== Daemon cycle end ===") def run_loop(interval: int = 3600) -> None: """Run daemon in a loop with configurable interval (default 1 hour).""" logger.info("Daemon started (interval=%ds)", interval) while True: run_once() time.sleep(interval)