Download apps/api/scripts/watch_run.py from aliroya/contiai: direct link, hf CLI and curl.
- Browser
- Download file 2.97 kB
-
https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/api/scripts/watch_run.py
- Command line
-
hf download hf://spaces/aliroya/contiai/apps/api/scripts/watch_run.py
-
curl -L -o watch_run.py https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/api/scripts/watch_run.py
2.97 kB
| # ruff: noqa: T201 | |
| """Watch one run to the end, printing each step as it changes state. | |
| Separate from the smoke scripts because the thing you need while chasing a | |
| failure is a live view of a run that already exists - not a new one. | |
| Usage: .venv/Scripts/python.exe scripts/watch_run.py <run-id> [--resume] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| import time | |
| sys.path.insert(0, ".") | |
| from scripts.smoke_local import ( # noqa: E402 | |
| ADMIN_EMAIL, | |
| client, | |
| existing_user_id, | |
| token_for, | |
| ) | |
| MARK = { | |
| "running": "..", | |
| "succeeded": "ok", | |
| "failed": "!!", | |
| "awaiting_review": "??", | |
| "skipped": "--", | |
| } | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("run_id") | |
| parser.add_argument("--resume", action="store_true") | |
| parser.add_argument("--timeout", type=int, default=5400) | |
| args = parser.parse_args() | |
| user = client(token_for(ADMIN_EMAIL, existing_user_id(ADMIN_EMAIL))) | |
| if args.resume: | |
| response = user.post(f"/v1/runs/{args.run_id}/resume") | |
| print(f"resume: {response.status_code}") | |
| if response.status_code != 202: | |
| print(response.text[:300]) | |
| return 1 | |
| seen: dict[str, str] = {} | |
| began = time.time() | |
| while time.time() - began < args.timeout: | |
| response = user.get(f"/v1/runs/{args.run_id}") | |
| if response.status_code != 200: | |
| print(f"! run unreadable: {response.status_code} {response.text[:160]}") | |
| time.sleep(6) | |
| continue | |
| body = response.json() | |
| for step in body.get("steps", []): | |
| key, state = step["step_key"], step["status"] | |
| if seen.get(key) != state and state != "pending": | |
| print(f" {MARK.get(state, state)} {key}") | |
| seen[key] = state | |
| if body["status"] in ("succeeded", "failed", "cancelled", "awaiting_review"): | |
| print(f"\nstatus: {body['status']}") | |
| for step in body.get("steps", []): | |
| if step["status"] == "failed": | |
| print(f"\nfailed at {step['step_key']}:") | |
| print(str(step.get("error"))[:2500]) | |
| if body["status"] == "succeeded": | |
| project_id = body["project_id"] | |
| items = user.get( | |
| f"/v1/projects/{project_id}/artifacts" | |
| ).json().get("items", []) | |
| print(f"\nartifacts: {len(items)}") | |
| for item in items: | |
| fetched = user.get(f"/v1/artifacts/{item['id']}") | |
| print(f" {item['title']} {item['format']} " | |
| f"{(item['size_bytes'] or 0):,} bytes " | |
| f"download={fetched.status_code}") | |
| return 0 if body["status"] in ("succeeded", "awaiting_review") else 1 | |
| time.sleep(8) | |
| print(f"! timed out after {args.timeout}s") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |