sjyangkevin commented on code in PR #54207:
URL: https://github.com/apache/airflow/pull/54207#discussion_r2318875192
##########
providers/jenkins/src/airflow/providers/jenkins/operators/jenkins_job_trigger.py:
##########
@@ -143,47 +143,46 @@ def poll_job_in_queue(self, location: str,
jenkins_server: Jenkins) -> int:
queue without having a build number assigned. We have to wait until the
job exits the queue to know its build number.
- To do so, we add ``/api/json`` (or ``/api/xml``) to the location
- returned by the ``build_job`` call, and poll this file. When an
- ``executable`` block appears in the response, the job execution would
- have started, and the field ``number`` would contains the build number.
+ To do so, we use get_queue_item to get information about a queued item
+
https://python-jenkins.readthedocs.io/en/latest/api.html#jenkins.Jenkins.get_queue_item
:param location: Location to poll, returned in the header of the
build_job call
:param jenkins_server: The jenkins server to poll
:return: The build_number corresponding to the triggered job
"""
- location += "/api/json"
- # TODO Use get_queue_info instead
- # once it will be available in python-jenkins (v > 0.4.15)
self.log.info("Polling jenkins queue at the url %s", location)
+
+ match = re.search(r"/queue/item/(\d+)/?", location)
+ if not match:
+ raise ValueError(f"Invalid queue location format: {location}")
+
+ queue_id = int(match.group(1))
+
+ self.log.info("Polling Jenkins queue item with ID %s", queue_id)
for attempt in range(self.max_try_before_job_appears):
if attempt:
time.sleep(self.sleep_time)
-
try:
- location_answer = jenkins_request_with_headers(
- jenkins_server, Request(method="POST", url=location)
- )
- # we don't want to fail the operator, this will continue to poll
- # until max_try_before_job_appears reached
+ json_response: dict = jenkins_server.get_queue_item(queue_id)
Review Comment:
Thanks for capturing it. I think it could happen. Will add a fix and
introduce a new test case for this scenario.
--
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]