diff --git a/apis/phabricator.py b/apis/phabricator.py index de38a84..3e329da 100644 --- a/apis/phabricator.py +++ b/apis/phabricator.py @@ -7,7 +7,7 @@ import json import platform -from components.utilities import retry +from components.utilities import retry, RETRY_TIMES from components.logging import logEntryExit, LogLevel from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider @@ -37,7 +37,7 @@ def __init__(self, config): self.url = config['url'] @logEntryExit - @retry + @retry(times=RETRY_TIMES) def submit_patches(self, bug_id, has_patches): phab_revisions = [] @@ -89,7 +89,7 @@ def submit_to_phabricator(rev_id): return phab_revisions @logEntryExit - @retry + @retry(times=RETRY_TIMES) def set_reviewer(self, phab_revision, phab_username): # We have to call a different API endpoint if this is a review group if phab_username[0] == "#": @@ -123,7 +123,7 @@ def set_reviewer(self, phab_revision, phab_username): raise Exception("Got an error from phabricator when trying to set reviewers to %s (%s) for %s: %s" % (phab_username, phid, phab_revision, result)) @logEntryExit - @retry + @retry(times=RETRY_TIMES) def abandon(self, phab_revision): cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"abandon", "value":true}],"objectIdentifier": "%s"}""" % phab_revision) cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url) diff --git a/apis/taskcluster.py b/apis/taskcluster.py index 70b1035..b024c43 100644 --- a/apis/taskcluster.py +++ b/apis/taskcluster.py @@ -12,7 +12,7 @@ from collections import defaultdict from urllib.parse import quote_plus -from components.utilities import retry, Struct, merge_dictionaries, PUSH_HEALTH_IGNORED_DICTS, PUSH_HEALTH_IGNORED_KEYS +from components.utilities import retry, RETRY_TIMES, Struct, merge_dictionaries, PUSH_HEALTH_IGNORED_DICTS, PUSH_HEALTH_IGNORED_KEYS from components.logging import logEntryExit, logEntryExitNoArgs, LogLevel from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider @@ -149,7 +149,7 @@ def _vcs_setup(self): self._vcs_setup_initialized = True @logEntryExit - @retry + @retry(times=RETRY_TIMES) def submit_to_try(self, library, platform_filter, recursed=0): self._vcs_setup() if not platform_filter: diff --git a/components/utilities.py b/components/utilities.py index 5eece93..a54f7da 100644 --- a/components/utilities.py +++ b/components/utilities.py @@ -144,8 +144,8 @@ def decorate(func): # Retry calling a function `times` times, sleeping between each tries, with an exponential backoff # This is to be used on API calls, that are likely to fail - -def retry(_func=None, *, times=10, sleep_s=1, exp=2): +RETRY_TIMES=10 +def retry(_func=None, *, times=RETRY_TIMES, sleep_s=1, exp=2): def decorator_retry(func): @functools.wraps(func) def wrapper_retry(*args, **kwargs): diff --git a/tests/functionality_all_platforms.py b/tests/functionality_all_platforms.py index 804548c..68a204b 100755 --- a/tests/functionality_all_platforms.py +++ b/tests/functionality_all_platforms.py @@ -16,6 +16,9 @@ sys.path.append(".") sys.path.append("..") +import components.utilities +components.utilities.RETRY_TIMES = 2 + from automation import Updatebot from components.utilities import Struct, raise_, AssertFalse diff --git a/tests/functionality_commitalert.py b/tests/functionality_commitalert.py index cde37b0..ee4ae60 100755 --- a/tests/functionality_commitalert.py +++ b/tests/functionality_commitalert.py @@ -12,6 +12,9 @@ sys.path.append(".") sys.path.append("..") +import components.utilities +components.utilities.RETRY_TIMES = 2 + from automation import Updatebot from components.utilities import Struct, NeverUseMeClass diff --git a/tests/functionality_two_platforms.py b/tests/functionality_two_platforms.py index 94cabe7..d68ee0e 100755 --- a/tests/functionality_two_platforms.py +++ b/tests/functionality_two_platforms.py @@ -16,6 +16,9 @@ sys.path.append(".") sys.path.append("..") +import components.utilities +components.utilities.RETRY_TIMES = 2 + from automation import Updatebot from components.utilities import Struct, raise_, AssertFalse @@ -34,6 +37,7 @@ from tests.mock_treeherder_server import MockTreeherderServerFactory, TYPE_HEALTH from tests.database import transform_db_config_to_tmp_db + try: from localconfig import localconfig except ImportError: