Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort QueueItem.block_until_building after 100 HTTPErrors #803

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jenkinsapi/jenkinsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions jenkinsapi/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down