summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-09-26 01:53:17 -0300
committerVictor Shyba <victor1984@riseup.net>2017-10-05 05:41:40 -0300
commit703036c34dbea644e7fb104ccaf812b00333bf4d (patch)
treea953171b7ff554da8385f6c6557fa0e2c1305c15 /src/leap
parent0c9bbaf5519e76841d141865f6ca76cba8d01d67 (diff)
[feature] retry during download
-- Related: #8822
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/soledad/client/_db/blobs.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py
index 76746c71..05802dab 100644
--- a/src/leap/soledad/client/_db/blobs.py
+++ b/src/leap/soledad/client/_db/blobs.py
@@ -31,6 +31,7 @@ from functools import partial
from twisted.logger import Logger
from twisted.enterprise import adbapi
from twisted.internet import defer
+from twisted.internet import error
import treq
@@ -338,10 +339,21 @@ class BlobManager(object):
for _ in range(min(self.concurrency_limit, len(docs_we_want))):
blob_id = docs_we_want.pop()
logger.info("Fetching new doc: %s" % blob_id)
- deferreds.append(self.get(blob_id, namespace))
+ d = self.__with_retry(self.get, blob_id, namespace)
+ deferreds.append(d)
yield defer.gatherResults(deferreds)
@defer.inlineCallbacks
+ def __with_retry(self, func, *args, **kwargs):
+ retries, max_retries = 0, 300
+ while retries < max_retries:
+ try:
+ yield func(*args, **kwargs)
+ break
+ except(error.ConnectError, error.ConnectionClosed):
+ retries += 1
+
+ @defer.inlineCallbacks
def sync(self, namespace=''):
yield self.refresh_sync_status_from_server(namespace)
yield self.fetch_missing(namespace)