Skip to content

Commit

Permalink
Better way of getting state once with a wait
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Aug 9, 2023
1 parent 6092b69 commit c083ee6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions spinnman/spalloc/spalloc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,12 @@ def _write_session_credentials_to_db(self, cur):
""", [(k1, k2, v) for (k1, k2), v in config.items()])

@overrides(SpallocJob.get_state)
def get_state(self):
obj = self._get(self._url).json()
def get_state(self, wait_for_change=False):
timeout = 10
if wait_for_change:
timeout = None
obj = self._get(
self._url, wait=wait_for_change, timeout=timeout).json()
return SpallocState[obj["state"]]

@overrides(SpallocJob.get_root_host)
Expand Down Expand Up @@ -603,7 +607,7 @@ def wait_for_state_change(self, old_state):

@overrides(SpallocJob.wait_until_ready)
def wait_until_ready(self):
state = SpallocState.UNKNOWN
state = self.get_state()
while state != SpallocState.READY:
state = self.wait_for_state_change(state)
if state == SpallocState.DESTROYED:
Expand Down
4 changes: 3 additions & 1 deletion spinnman/spalloc/spalloc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ class SpallocJob(object, metaclass=AbstractBase):
__slots__ = ()

@abstractmethod
def get_state(self) -> SpallocState:
def get_state(self, wait_for_change=False) -> SpallocState:
"""
Get the current state of the machine.
:param bool wait_for_change: Whether to wait for a change in state
:rtype: SpallocState
"""

Expand Down

0 comments on commit c083ee6

Please sign in to comment.