from __future__ import annotations import logging import time from app.core.config import settings from app.services.sync_push_service import pull_detect_task_batch_now, push_runtime_projection_now logger = logging.getLogger("domaincheck.sync_agent") def main() -> None: logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", ) interval = max(10, int(settings.sync_poll_interval_seconds or 30)) logger.info( "sync agent started: node=%s source=%s target=%s interval=%ss enabled=%s", settings.node_code, settings.sync_source_region, settings.sync_target_region, interval, settings.sync_push_enabled, ) while True: try: ok, message, data = push_runtime_projection_now() logger.info("sync tick: ok=%s message=%s data=%s", ok, message, data) pull_ok, pull_message, pull_data = pull_detect_task_batch_now() logger.info("task pull tick: ok=%s message=%s data=%s", pull_ok, pull_message, pull_data) except Exception as exc: logger.exception("sync tick failed: %s", exc) time.sleep(interval) if __name__ == "__main__": main()