(args: argparse.Namespace, *, base_url: str, run_id: str, progress_label: str = "workflow-run")
| 733 | |
| 734 | |
| 735 | def _poll_workflow_run(args: argparse.Namespace, *, base_url: str, run_id: str, progress_label: str = "workflow-run") -> tuple[dict[str, Any], str]: |
| 736 | deadline = time.monotonic() + args.timeout |
| 737 | last_status: dict[str, Any] = {} |
| 738 | while time.monotonic() < deadline: |
| 739 | status = _request_json("GET", f"{base_url}/workflow-runs/{urllib.parse.quote(str(run_id))}", timeout=args.request_timeout) |
| 740 | last_status = status if isinstance(status, dict) else {"raw": status} |
| 741 | state = last_status.get("status") |
| 742 | if state == "done": |
| 743 | return last_status, _workflow_workspace_path(last_status) |
| 744 | if state in {"error", "cancelled"}: |
| 745 | raise ModlyCliError(f"Workflow run {run_id} ended with status {state}: {last_status}", code="WORKFLOW_RUN_FAILED") |
| 746 | if getattr(args, "progress", False) and not getattr(args, "quiet", False): |
| 747 | progress = last_status.get("progress", 0) |
| 748 | step = last_status.get("step", "") |
| 749 | print(json.dumps({"phase": progress_label, "run_id": run_id, "status": state, "progress": progress, "step": step}), file=sys.stderr) |
| 750 | time.sleep(args.poll) |
| 751 | |
| 752 | raise ModlyCliError(f"Timed out waiting for workflow run {run_id}. Last status: {last_status}", code="TIMEOUT") |
| 753 | |
| 754 | |
| 755 | def _run_workflow_run( |
no test coverage detected