fix: client result command uses /v1/jobs/{id}/result endpoint

This commit is contained in:
oib
2026-03-05 07:15:02 +01:00
parent c3e5faa62a
commit 89bc1ee557

View File

@@ -175,35 +175,39 @@ def result(ctx, job_id: str, wait: bool, timeout: int):
start = time.time() start = time.time()
while True: while True:
try: try:
with httpx.Client() as client: with httpx.Client() as http:
response = client.get( # Try the dedicated result endpoint first
f"{config.coordinator_url}/v1/jobs/{job_id}", response = http.get(
f"{config.coordinator_url}/v1/jobs/{job_id}/result",
headers={"X-Api-Key": config.api_key or ""} headers={"X-Api-Key": config.api_key or ""}
) )
if response.status_code == 200: if response.status_code == 200:
job_data = response.json() result_data = response.json()
state = job_data.get("state", "UNKNOWN") success(f"Job {job_id} completed")
output(result_data, ctx.obj['output_format'])
if state == "COMPLETED": return
result_data = job_data.get("result") elif response.status_code == 425:
if result_data: # Job not ready yet
success(f"Job {job_id} completed") if wait and (time.time() - start) < timeout:
output(result_data, ctx.obj['output_format'])
else:
output({"job_id": job_id, "state": state, "result": None}, ctx.obj['output_format'])
return
elif state in ("FAILED", "EXPIRED"):
error(f"Job {job_id} {state}: {job_data.get('error', 'no details')}")
return
elif wait and (time.time() - start) < timeout:
time.sleep(3) time.sleep(3)
continue continue
# Check status for more info
status_resp = http.get(
f"{config.coordinator_url}/v1/jobs/{job_id}",
headers={"X-Api-Key": config.api_key or ""}
)
if status_resp.status_code == 200:
job_data = status_resp.json()
output({"job_id": job_id, "state": job_data.get("state", "UNKNOWN"), "message": "Job not yet completed"}, ctx.obj['output_format'])
else: else:
output({"job_id": job_id, "state": state, "message": "Job not yet completed"}, ctx.obj['output_format']) error(f"Job not ready (425)")
return return
elif response.status_code == 404:
error(f"Job {job_id} not found")
return
else: else:
error(f"Failed to get job: {response.status_code}") error(f"Failed to get result: {response.status_code}")
return return
except Exception as e: except Exception as e:
error(f"Network error: {e}") error(f"Network error: {e}")