feat: configurable exec timeout per request (--timeout flag, default 30s)
This commit is contained in:
parent
1c0af1693b
commit
537ed95a3c
5 changed files with 44 additions and 17 deletions
|
|
@ -38,14 +38,14 @@ def _headers() -> dict:
|
|||
return {"X-Api-Key": API_KEY, "Content-Type": "application/json"}
|
||||
|
||||
|
||||
def _req(method: str, path: str, **kwargs):
|
||||
def _req(method: str, path: str, timeout: int = 30, **kwargs):
|
||||
url = f"{BASE_URL}{path}"
|
||||
try:
|
||||
resp = requests.request(method, url, headers=_headers(), timeout=30, **kwargs)
|
||||
resp = requests.request(method, url, headers=_headers(), timeout=timeout, **kwargs)
|
||||
except requests.exceptions.ConnectionError as exc:
|
||||
sys.exit(f"[helios-remote] CONNECTION ERROR: Cannot reach {url}\n → {exc}")
|
||||
except requests.exceptions.Timeout:
|
||||
sys.exit(f"[helios-remote] TIMEOUT: {url} did not respond within 30 s")
|
||||
sys.exit(f"[helios-remote] TIMEOUT: {url} did not respond within {timeout} s")
|
||||
|
||||
if not resp.ok:
|
||||
body = resp.text[:1000] if resp.text else "(empty body)"
|
||||
|
|
@ -141,7 +141,10 @@ def cmd_exec(args):
|
|||
"""Run a shell command on the remote session."""
|
||||
sid = resolve_session(args.session_id)
|
||||
command = " ".join(args.parts) if isinstance(args.parts, list) else args.parts
|
||||
resp = _req("POST", f"/sessions/{sid}/exec", json={"command": command})
|
||||
body = {"command": command}
|
||||
if args.timeout:
|
||||
body["timeout_ms"] = args.timeout * 1000 # seconds → ms
|
||||
resp = _req("POST", f"/sessions/{sid}/exec", json=body, timeout=max(35, (args.timeout or 30) + 5))
|
||||
data = resp.json()
|
||||
|
||||
stdout = data.get("stdout") or data.get("output") or ""
|
||||
|
|
@ -343,6 +346,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|||
ep.add_argument("session_id")
|
||||
ep.add_argument("parts", nargs=argparse.REMAINDER, metavar="command",
|
||||
help="Command (and arguments) to execute")
|
||||
ep.add_argument("--timeout", type=int, default=None, metavar="SECONDS",
|
||||
help="Timeout in seconds (default: 30). Use higher for long downloads etc.")
|
||||
|
||||
cp = sub.add_parser("click", help="Send a mouse click")
|
||||
cp.add_argument("session_id")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue