jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/476294 )
Change subject: [IMPR] Let maximum retry wait time be configurable ......................................................................
[IMPR] Let maximum retry wait time be configurable
Introduce retry_max variable in config2.py and use it in several modules
Change-Id: Ie85ee8a76fad9bc553fb8a8f783c002649005a31 --- M pywikibot/config2.py M pywikibot/data/api.py M pywikibot/data/sparql.py M pywikibot/throttle.py 4 files changed, 10 insertions(+), 8 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 695ef98..dcda22f 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -672,6 +672,8 @@ max_retries = 15 # Minimum time to wait before resubmitting a failed API request. retry_wait = 5 +# Maximum time to wait before resubmitting a failed API request. +retry_max = 120
# ############# TABLE CONVERSION BOT SETTINGS ##############
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 64223ce..bb02747 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1360,7 +1360,7 @@ errors, defaults to config.max_retries. @param retry_wait: (optional) Minimum time in seconds to wait after an error, defaults to config.retry_wait seconds (doubles each retry - until max of 120 seconds is reached). + until config.retry_max seconds is reached). @param use_get: (optional) Use HTTP GET request if possible. If False it uses a POST request. If None, it'll try to determine via action=paraminfo if the action requires a POST. @@ -2282,8 +2282,8 @@ pywikibot.warning('Waiting %s seconds before retrying.' % self.retry_wait) pywikibot.sleep(self.retry_wait) - # double the next wait, but do not exceed 120 seconds - self.retry_wait = min(120, self.retry_wait * 2) + # double the next wait, but do not exceed config.retry_max seconds + self.retry_wait = min(config.retry_max, self.retry_wait * 2)
class CachedRequest(Request): diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py index 9b9eb0e..ebe6605 100644 --- a/pywikibot/data/sparql.py +++ b/pywikibot/data/sparql.py @@ -52,7 +52,7 @@ @type max_retries: int @param retry_wait: (optional) Minimum time in seconds to wait after an error, defaults to config.retry_wait seconds (doubles each retry - until max of 120 seconds is reached). + until config.retry_max is reached). @type retry_wait: float """ # default to Wikidata @@ -162,8 +162,8 @@ raise TimeoutError('Maximum retries attempted without success.') warning('Waiting {0} seconds before retrying.'.format(self.retry_wait)) sleep(self.retry_wait) - # double the next wait, but do not exceed 120 seconds - self.retry_wait = min(120, self.retry_wait * 2) + # double the next wait, but do not exceed config.retry_max seconds + self.retry_wait = min(config.retry_max, self.retry_wait * 2)
def ask(self, query, headers=DEFAULT_HEADERS): """ diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index 042c6e5..23930ab 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -301,8 +301,8 @@ started = time.time() with self.lock: waittime = self.retry_after or lagtime or 5 - # wait not more than 120 seconds - delay = min(waittime, 120) + # wait not more than retry_max seconds + delay = min(waittime, config.retry_max) # account for any time we waited while acquiring the lock wait = delay - (time.time() - started) self.wait(wait)