Skip to content

Commit

Permalink
Better options
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed Nov 30, 2023
1 parent 6847e23 commit c281490
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
21 changes: 11 additions & 10 deletions spinnman/spalloc/spalloc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,23 +615,24 @@ def open_udp_listener_connection(self) -> UDPConnection:

@overrides(SpallocJob.wait_for_state_change)
def wait_for_state_change(self, old_state: SpallocState,
timeout: Optional[int] = None) -> SpallocState:
while old_state != SpallocState.DESTROYED:
obj = self._get(self._url, wait="true", timeout=timeout).json()
n_retries: Optional[int] = None) -> SpallocState:
retries = 0
while (old_state != SpallocState.DESTROYED and
(n_retries is None or retries < n_retries)):
retries += 1
obj = self._get(self._url, wait="true", timeout=None).json()
s = SpallocState[obj["state"]]
if s != old_state or s == SpallocState.DESTROYED:
return s
return old_state

@overrides(SpallocJob.wait_until_ready)
def wait_until_ready(self, timeout: Optional[int] = None,
n_retries: Optional[int] = None):
def wait_until_ready(self, n_retries: Optional[int] = None):
state = self.get_state()
retries = 0
while (state != SpallocState.READY and
(n_retries is None or retries < n_retries)):
retries += 1
state = self.wait_for_state_change(state, timeout=timeout)
while state != SpallocState.READY:
state = self.wait_for_state_change(state, n_retries=n_retries)
if state == SpallocState.READY or n_retries is not None:
return
if state == SpallocState.DESTROYED:
raise SpallocException("job was unexpectedly destroyed")

Expand Down
13 changes: 5 additions & 8 deletions spinnman/spalloc/spalloc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ def create_transceiver(self) -> Transceiver:

@abstractmethod
def wait_for_state_change(self, old_state: SpallocState,
timeout: Optional[int] = None) -> SpallocState:
n_retries: Optional[int] = None) -> SpallocState:
"""
Wait until the allocation is not in the given old state.
:param SpallocState old_state:
The state that we are looking to change out of.
:param timeout:
The time to wait, or None to wait forever
:type timeout: int or None
:param n_retries:
The number of times to retry or None to try forever
:type n_retries: int or None
:return: The state that the allocation is now in.
.. note::
Expand All @@ -159,13 +159,10 @@ def wait_for_state_change(self, old_state: SpallocState,
raise NotImplementedError()

@abstractmethod
def wait_until_ready(self, timeout: Optional[int] = None,
n_retries: Optional[int] = None):
def wait_until_ready(self, n_retries: Optional[int] = None):
"""
Wait until the allocation is in the ``READY`` state.
:param timeout: The timeout or None to wait forever
:type timeout: int or None
:param n_retries:
The number of times to retry, or None to retry forever
:type n_retries: int or None
Expand Down

0 comments on commit c281490

Please sign in to comment.