diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-09-26 01:53:17 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-10-05 05:41:40 -0300 |
commit | 703036c34dbea644e7fb104ccaf812b00333bf4d (patch) | |
tree | a953171b7ff554da8385f6c6557fa0e2c1305c15 /src/leap | |
parent | 0c9bbaf5519e76841d141865f6ca76cba8d01d67 (diff) |
[feature] retry during download
-- Related: #8822
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/soledad/client/_db/blobs.py | 14 |
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) |