Seokyun-Ha commented on code in PR #34071:
URL: https://github.com/apache/airflow/pull/34071#discussion_r1316891222


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -404,6 +479,40 @@ def start_cluster(self, json: dict) -> None:
         """
         self._do_api_call(START_CLUSTER_ENDPOINT, json)
 
+    def activate_cluster(self, json: dict, polling: int, timeout: int | None = 
None) -> None:
+        """
+        Start the cluster, and wait for it to be ready.
+
+        :param json: json dictionary containing cluster specification.
+        :param polling: polling interval in seconds.
+        :param timeout: timeout in seconds. -1 means no timeout.
+        """
+        cluster_id = json['cluster_id']
+
+        api_called = False
+        elapsed_time = 0
+
+        while True:
+            run_state = self.get_cluster_state(cluster_id)
+
+            if run_state.is_running:
+                return
+            elif run_state.is_terminal:
+                if not api_called:
+                    self.start_cluster(json)
+                    api_called = True
+                else:
+                    raise AirflowException(
+                        f"Cluster {cluster_id} start failed with 
'{run_state.state}' state: {run_state.state_message}"
+                    )
+
+            # wait for cluster to start
+            time.sleep(polling)
+
+            elapsed_time += polling
+            if timeout and elapsed_time <= timeout:
+                raise AirflowException(f"Cluster {cluster_id} start timed out 
after {timeout} seconds")

Review Comment:
   I've changed it :)
   
https://github.com/apache/airflow/pull/34071/commits/0745545a160f54fbe6f8e42b94a839fe0655945a



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to