Job 1788347373752

Command: python -c "import sys,inspect;sys.path.insert(0,'..');import sheet_relay as s;print(inspect.getsource(s.run_loop))"
Directory: projects
Status: SUCCESS
Exit code: 0

Cancel Job Rerun Command Refresh

def run_loop():
    cfg = require_config()
    last_heartbeat = 0
    log("relay starting")
    while True:
        try:
            if time.time() - last_heartbeat > 30:
                heartbeat(cfg, bridge_health(cfg))
                last_heartbeat = time.time()
            monitor_verifies(cfg)
            _status, data = http_json(web_app_url(cfg, "poll"), timeout=45)
            command = data.get("command")
            if not command:
                time.sleep(float(cfg.get("poll_seconds", 3)))
                continue
            log(f"claimed command id={command.get('id')} action={command.get('action')}")
            task_id = ""
            try:
                task_id = str(json.loads(command.get("payload_json") or "{}").get("task_id", ""))
            except (TypeError, ValueError):
                pass
            record_task_event(task_id, "command_started", command_id=command.get("id"), action=command.get("action"))
            try:
                command_result = execute_command(cfg, command)
                record_task_event(task_id, "command_completed" if command_result.get("status") == "done" else "command_failed", command_id=command.get("id"), action=command.get("action"), relay_status=command_result.get("status"), http_status=command_result.get("http_status"))
                send_result(cfg, command_result)
            except Exception as exc:
                record_task_event(task_id, "command_failed", command_id=command.get("id"), action=command.get("action"), error=type(exc).__name__)
                send_result(cfg, result(command.get("id", ""), "error", "", "", str(exc), time.time()))
        except KeyboardInterrupt:
            log("relay stopped by keyboard interrupt")
            return
        except Exception as exc:
            log(f"relay error: {type(exc).__name__}: {exc}")
            time.sleep(10)