import asyncio import logging import os from collector import collect_sources from db import init_db, upsert_items from processor import process_items logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s") log = logging.getLogger(__name__) COLLECT_INTERVAL_SECONDS = int(os.environ.get("INFO_ENGINE_INTERVAL_SECONDS", "900")) async def run_once() -> int: raw_items = await collect_sources() processed = process_items(raw_items) inserted = await upsert_items(processed) return inserted async def main(): await init_db() log.info("Info engine started (interval=%ss)", COLLECT_INTERVAL_SECONDS) while True: try: inserted = await run_once() log.info("Info engine cycle complete (inserted=%d)", inserted) except Exception as exc: log.error("Info engine cycle failed: %s", exc) await asyncio.sleep(COLLECT_INTERVAL_SECONDS) if __name__ == "__main__": asyncio.run(main())