add state machine utility parameter for clarity when debugging

master
papuSpartan 2024-05-26 21:51:35 -05:00
parent 00d0e1a11a
commit 54a1f66c88
2 changed files with 11 additions and 3 deletions

View File

@ -707,11 +707,19 @@ class Worker:
logger.error(f"{err_msg}: {response}")
return False
def set_state(self, state: State):
def set_state(self, state: State, expect_cycle: bool = False):
"""
Updates the state of a worker if considered a valid operation
Args:
state: the new state to try transitioning to
expect_cycle: whether this transition might be a no-op/self-loop
"""
state_cache = self.state
def transition(ns: State):
if ns == self.state:
if ns == self.state and expect_cycle is False:
logger.debug(f"{self.label}: potentially redundant transition {self.state.name} -> {ns.name}")
return

View File

@ -725,7 +725,7 @@ class World:
msg = f"worker '{worker.label}' is online"
logger.info(msg)
gradio.Info("Distributed: "+msg)
worker.set_state(State.IDLE)
worker.set_state(State.IDLE, expect_cycle=True)
else:
msg = f"worker '{worker.label}' is unreachable"
logger.info(msg)