From ad98b9e2942b9a9c708213177615c4c571c50074 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Wed, 18 Dec 2019 09:37:36 +0100 Subject: [PATCH] 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 --- distgit_bugzilla_sync/script.py | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/distgit_bugzilla_sync/script.py b/distgit_bugzilla_sync/script.py index ce7eda2..bd9b099 100644 --- a/distgit_bugzilla_sync/script.py +++ b/distgit_bugzilla_sync/script.py @@ -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)