in blogs/finspace_redshift-2021-09/finspace.py [0:0]
def wait_for_status(self, clusterId: str, status: str, sleep_sec=10, max_wait_sec=900):
"""
Function polls service until cluster is in desired status.
:param clusterId: the cluster's ID
:param status: desired status for clsuter to reach
:
"""
total_wait = 0
while True and total_wait < max_wait_sec:
resp = self.client.list_clusters()
this_cluster = None
# is this the cluster?
for c in resp['clusters']:
if clusterId == c['clusterId']:
this_cluster = c
if this_cluster is None:
print(f"clusterId:{clusterId} not found")
return (None)
this_status = this_cluster['clusterStatus']['state']
if this_status.upper() != status.upper():
print(f"Cluster status is {this_status}, waiting {sleep_sec} sec ...")
time.sleep(sleep_sec)
total_wait = total_wait + sleep_sec
continue
else:
return (this_cluster)