From ca442d7ec3fd07e959ca7f1083210bd3eedcf06c Mon Sep 17 00:00:00 2001 From: Yonghee Han Date: Fri, 2 Feb 2018 13:58:28 +0900 Subject: [PATCH] Workaround code for HTTP Error 408 PROBLEM : HTTP Error 408: Request Timeout SOLUTION : Retry for Error exception Change-Id: I09311b0c06c215b9d10f6c97239f7a06aebb6b8f --- job_repa.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/job_repa.py b/job_repa.py index cefd655..a63eea4 100644 --- a/job_repa.py +++ b/job_repa.py @@ -32,6 +32,7 @@ import xml.etree.ElementTree as ElementTree from gbp.git.repository import GitRepositoryError from osc import core +from time import sleep from common.gerrit import Gerrit, get_gerrit_event, GerritError, is_ref_deleted from common.git import Git, clone_gitproject @@ -114,21 +115,32 @@ def accept_or_reject(build, prerelease_proj, git_tag, state, comment=''): message = "SR %s is set to %s" % (reqid, state) if comment: message += comment - build.set_sr_state(reqid, state=state, - message=str(message), force=True) - print 'set SR state to', state + + retry_count = 3 + ret = "" + while retry_count >= 0: + try: + r = build.set_sr_state(reqid, state=state, + message=str(message), force=True) + print 'set SR state to', state, r + ret = "" + break + except Exception as err: + print 'set SR error: %s Retry...' %(err) + retry_count -= 1 + ret = str(err) + sleep(1) + return ret def repa_reject(build, proj, git_tag, comment=''): try: - accept_or_reject(build, proj, git_tag, 'declined', comment) - return "" + return accept_or_reject(build, proj, git_tag, 'declined', comment) except Exception as err: return str(err) def repa_accept(build, proj, git_tag, comment=''): try: - accept_or_reject(build, proj, git_tag, 'accepted', comment) - return "" + return accept_or_reject(build, proj, git_tag, 'accepted', comment) except Exception as err: return str(err) -- 2.7.4