diff --git a/src/codeflare_sdk/cluster/cluster.py b/src/codeflare_sdk/cluster/cluster.py index aff3ea6b..831d8c68 100644 --- a/src/codeflare_sdk/cluster/cluster.py +++ b/src/codeflare_sdk/cluster/cluster.py @@ -369,36 +369,33 @@ def wait_ready(self, timeout: Optional[int] = None, dashboard_check: bool = True Checks every five seconds. """ print("Waiting for requested resources to be set up...") - ready = False - dashboard_ready = False - status = None time = 0 - while not ready: + while True: + if timeout and time >= timeout: + raise TimeoutError( + f"wait() timed out after waiting {timeout}s for cluster to be ready" + ) status, ready = self.status(print_to_console=False) if status == CodeFlareClusterStatus.UNKNOWN: print( "WARNING: Current cluster status is unknown, have you run cluster.up yet?" ) - if not ready: - if timeout and time >= timeout: - raise TimeoutError( - f"wait() timed out after waiting {timeout}s for cluster to be ready" - ) - sleep(5) - time += 5 + if ready: + break + sleep(5) + time += 5 print("Requested cluster is up and running!") - while dashboard_check and not dashboard_ready: - dashboard_ready = self.is_dashboard_ready() - if not dashboard_ready: - if timeout and time >= timeout: - raise TimeoutError( - f"wait() timed out after waiting {timeout}s for dashboard to be ready" - ) - sleep(5) - time += 5 - if dashboard_ready: - print("Dashboard is ready!") + while dashboard_check: + if timeout and time >= timeout: + raise TimeoutError( + f"wait() timed out after waiting {timeout}s for dashboard to be ready" + ) + if self.is_dashboard_ready(): + print("Dashboard is ready!") + break + sleep(5) + time += 5 def details(self, print_to_console: bool = True) -> RayCluster: cluster = _copy_to_ray(self)