Be more resilient to transient bugzilla error

ie: retry a few time (up to 5 times) with a 20 seconds pause between
each attempt before raising an exception.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2019-12-18 09:37:36 +01:00
parent 7b1f707efc
commit ad98b9e294

View file

@ -446,9 +446,24 @@ class BugzillaProxy:
# FIXME: initialowner has been made mandatory for some
# reason. Asking dkl why.
data['initialowner'] = owner_email
def edit_component(data, num_attempts=5):
for i in range(num_attempts):
try:
self.server.editcomponent(data)
break
except Exception as e:
if i >= num_attempts - 1:
raise
if self.config['verbose']:
print(f" ERROR {e}")
print(" - Query failed, going to try again in 20 seconds")
# Wait 20 seconds and try again
time.sleep(20)
if not self.config["dryrun"]:
try:
self.server.editcomponent(data)
edit_component(data)
except xmlrpc.client.Fault as e:
# Output something useful in args
e.args = (data, e.faultCode, e.faultString)
@ -456,6 +471,7 @@ class BugzillaProxy:
except xmlrpc.client.ProtocolError as e:
e.args = ('ProtocolError', e.errcode, e.errmsg)
raise
if owner_changed:
self.update_open_bugs(
new_poc=owner_email,
@ -500,9 +516,24 @@ class BugzillaProxy:
print(f"[ADDCOMP] {bz_product_name}/{package} {key} set to FAS name(s) `{value}`")
else:
print(f"[ADDCOMP] {bz_product_name}/{package} {key} set to {data.get(key)}")
def add_component(data, num_attempts=5):
for i in range(num_attempts):
try:
self.server.addcomponent(data)
break
except Exception as e:
if i >= num_attempts - 1:
raise
if self.config['verbose']:
print(f" ERROR {e}")
print(" - Query failed, going to try again in 20 seconds")
# Wait 20 seconds and try again
time.sleep(20)
if not self.config["dryrun"]:
try:
self.server.addcomponent(data)
add_component(data)
except xmlrpc.client.Fault as e:
# Output something useful in args
e.args = (data, e.faultCode, e.faultString)