jenkins-bot merged this change.

View Change

Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
[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(-)

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)

To view, visit change 476294. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie85ee8a76fad9bc553fb8a8f783c002649005a31
Gerrit-Change-Number: 476294
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)