Skip to content

Commit de986db

Browse files
committed
[iris] Return typed JobState from job_state / state_only
1 parent 3a73fec commit de986db

2 files changed

Lines changed: 25 additions & 45 deletions

File tree

lib/iris/src/iris/client/client.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,14 @@ def status(self) -> job_pb2.JobStatus:
224224
"""
225225
return self._client._cluster_client.get_job_status(self._job_id)
226226

227-
def state_only(self) -> int:
227+
def state_only(self) -> job_pb2.JobState:
228228
"""Lightweight state query that avoids loading tasks/attempts/workers."""
229-
states = self._client._cluster_client.get_job_states([self._job_id])
230-
wire_id = self._job_id.to_wire()
231-
if wire_id not in states:
232-
raise KeyError(f"Job {wire_id} not found")
233-
return states[wire_id]
229+
return self._client.job_state(self._job_id)
234230

235231
@property
236232
def state(self) -> job_pb2.JobState:
237233
"""Get current job state via the lightweight state-only RPC."""
238-
return cast(job_pb2.JobState, self.state_only())
234+
return self.state_only()
239235

240236
def tasks(self) -> list[Task]:
241237
"""Get all tasks for this job.
@@ -706,7 +702,7 @@ def status(self, job_id: JobName) -> job_pb2.JobStatus:
706702
"""
707703
return self._cluster_client.get_job_status(job_id)
708704

709-
def job_state(self, job_id: JobName) -> int:
705+
def job_state(self, job_id: JobName) -> job_pb2.JobState:
710706
"""Lightweight state query that avoids loading tasks/attempts/workers.
711707
712708
Prefer this over ``status(job_id).state`` for polling loops.
@@ -715,7 +711,7 @@ def job_state(self, job_id: JobName) -> int:
715711
wire_id = job_id.to_wire()
716712
if wire_id not in states:
717713
raise KeyError(f"Job {wire_id} not found")
718-
return states[wire_id]
714+
return cast(job_pb2.JobState, states[wire_id])
719715

720716
def terminate(self, job_id: JobName) -> None:
721717
"""Terminate a running job.

0 commit comments

Comments
 (0)