#!/usr/bin/env python3 """Retry only persisted idempotent status reports, never repeat model work.""" import argparse import json from pathlib import Path import time from report import flush from worker import atomic_json,session_lock def main(): p=argparse.ArgumentParser(description=__doc__) p.add_argument('--config',required=True) p.add_argument('--once',action='store_true') a=p.parse_args() bridge=json.loads(Path(a.config).read_text(encoding='utf-8-sig')) cfg=json.loads(Path(bridge['task_report_config']).read_text(encoding='utf-8-sig')) health=Path(bridge['state_file']).parent/'report_relay-health.json' with session_lock('task-report-relay:'+json.dumps(cfg,sort_keys=True)): while True: try: counts=flush(cfg) atomic_json(health,{'status':'ok' if not counts['pending'] and not counts['blocked'] else 'failed', 'updated':time.time(),'reports':counts}) except Exception: atomic_json(health,{'status':'failed','updated':time.time(),'reason':'Inspect private report outbox'}) if a.once:raise if a.once:return time.sleep(5) if __name__=='__main__':main()