From b1017afad7b80c0870102d9d2ba03ae76bd0ddbb Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Wed, 9 Dec 2020 17:41:04 +0100 Subject: [PATCH] Abort QueueItem.block_until_building after 100 HTTPErrors --- jenkinsapi/jenkinsbase.py | 4 ++-- jenkinsapi/queue.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jenkinsapi/jenkinsbase.py b/jenkinsapi/jenkinsbase.py index 939f0d9a..0372f9bd 100644 --- a/jenkinsapi/jenkinsbase.py +++ b/jenkinsapi/jenkinsbase.py @@ -78,8 +78,8 @@ def get_data(self, url, params=None, tree=None): response = requester.get_url(url, params) if response.status_code != 200: - logger.error('Failed request at %s with params: %s %s', - url, params, tree if tree else '') + logger.error('Failed request at %s with params: %s %s - HTTP %s', + url, params, tree if tree else '', response.status_code) response.raise_for_status() try: return ast.literal_eval(response.text) diff --git a/jenkinsapi/queue.py b/jenkinsapi/queue.py index 1fe5c61d..58ab97dc 100644 --- a/jenkinsapi/queue.py +++ b/jenkinsapi/queue.py @@ -87,6 +87,8 @@ class QueueItem(JenkinsBase): """An individual item in the queue """ + MAX_RETRIES = 100 # if set, abort after this number of HTTPError + def __init__(self, baseurl, jenkins_obj): self.jenkins = jenkins_obj JenkinsBase.__init__(self, baseurl) @@ -142,6 +144,7 @@ def block_until_complete(self, delay=5): return build.block_until_complete(delay=delay) def block_until_building(self, delay=5): + retries = 0 while True: try: self.poll() @@ -150,7 +153,10 @@ def block_until_building(self, delay=5): time.sleep(delay) continue except HTTPError as http_error: + if self.MAX_RETRIES and retries >= self.MAX_RETRIES: + raise http_error log.debug(str(http_error)) + retries += 1 time.sleep(delay) continue