moiseenkov commented on code in PR #37998:
URL: https://github.com/apache/airflow/pull/37998#discussion_r1521429853


##########
airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -512,6 +513,36 @@ def get_job(self, job_name: str, namespace: str) -> V1Job:
         """
         return self.batch_v1_client.read_namespaced_job(name=job_name, 
namespace=namespace, pretty=True)
 
+    def get_job_status(self, job_name: str, namespace: str) -> V1Job:
+        """Get job with status of specified name from Google Cloud.
+
+        :param job_name: Name of Job to fetch.
+        :param namespace: Namespace of the Job.
+        :return: Job object
+        """
+        return self.batch_v1_client.read_namespaced_job_status(
+            name=job_name, namespace=namespace, pretty=True
+        )
+
+    def wait_job_until_complete(self, job_name: str, namespace: str, 
job_poll_interval: float = 10) -> V1Job:
+        """Block job of specified name from Google Cloud until it is complete.
+
+        :param job_name: Name of Job to fetch.
+        :param namespace: Namespace of the Job.
+        :param job_poll_interval: Interval in seconds between polling the job 
status
+        :return: Job object
+        """
+        while True:
+            self.log.info("Requesting status for the job '%s' ", job_name)
+            job: V1Job = self.get_job_status(job_name=job_name, 
namespace=namespace)
+            if conditions := job.status.conditions:
+                if condition_complete := next((c for c in conditions if c.type 
== "Complete"), None):
+                    if condition_complete.status:
+                        self.log.info("The job '%s' is complete.", job_name)

Review Comment:
   Yes, you're right. Added handle for this case. Thanks for noticing!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to