You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/04/07 02:45:34 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #22802: Bug Fix for `apache-airflow-providers-jenkins` `JenkinsJobTriggerOperator`

uranusjr commented on code in PR #22802:
URL: https://github.com/apache/airflow/pull/22802#discussion_r844586382


##########
airflow/providers/jenkins/operators/jenkins_job_trigger.py:
##########
@@ -153,21 +153,30 @@ def poll_job_in_queue(self, location: str, jenkins_server: Jenkins) -> int:
         # once it will be available in python-jenkins (v > 0.4.15)
         self.log.info('Polling jenkins queue at the url %s', location)
         while try_count < self.max_try_before_job_appears:
-            location_answer = jenkins_request_with_headers(
-                jenkins_server, Request(method='POST', url=location)
-            )
-            if location_answer is not None:
-                json_response = json.loads(location_answer['body'])
-                if (
-                    'executable' in json_response
-                    and json_response['executable'] is not None
-                    and 'number' in json_response['executable']
-                ):
-                    build_number = json_response['executable']['number']
-                    self.log.info('Job executed on Jenkins side with the build number %s', build_number)
-                    return build_number
-            try_count += 1
-            time.sleep(self.sleep_time)
+            try:
+                location_answer = jenkins_request_with_headers(
+                    jenkins_server, Request(method='POST', url=location)
+                )
+                if location_answer is not None:
+                    json_response = json.loads(location_answer['body'])
+                    if (
+                        'executable' in json_response
+                        and json_response['executable'] is not None
+                        and 'number' in json_response['executable']
+                    ):
+                        build_number = json_response['executable']['number']
+                        self.log.info('Job executed on Jenkins side with the build number %s', build_number)
+                        return build_number
+                try_count += 1
+                time.sleep(self.sleep_time)
+
+            # we don't want to fail the operator, this will continue to poll
+            # until max_try_before_job_appears reached
+            except (HTTPError, JenkinsException) as ex:

Review Comment:
   When are these exceptions raised, respectively? This try-catch block seems too big, a lot of the wrapped code is response processing that should be outside of this block, from what I can tell.



-- 
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-unsubscribe@airflow.apache.org

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