""" Abstract base for all collectors. Each collector must implement `collect()` which writes to the DB and returns a summary dict. """ from abc import ABC, abstractmethod from datetime import datetime, timezone import logging logger = logging.getLogger(__name__) class BaseCollector(ABC): name: str = "base" def run(self) -> dict: start = datetime.now(timezone.utc) logger.info("[%s] collection started", self.name) try: result = self.collect() elapsed = (datetime.now(timezone.utc) - start).total_seconds() logger.info("[%s] done in %.1fs — %s", self.name, elapsed, result) return result except Exception as exc: logger.exception("[%s] collection failed: %s", self.name, exc) return {"error": str(exc)} @abstractmethod def collect(self) -> dict: """Fetch data and persist to DB. Return a summary dict.""" ...