changes from code review

This commit is contained in:
Victor Shyba 2018-06-18 03:53:17 -03:00
parent ad96b006f9
commit ec140d5d8a

View file

@ -26,6 +26,7 @@ class HTTPBlobDownloader(object):
def start(self): def start(self):
if not self.running and self.blob_hashes and self.servers: if not self.running and self.blob_hashes and self.servers:
return self.looping_call.start(self.interval, now=True) return self.looping_call.start(self.interval, now=True)
defer.succeed(None)
def stop(self): def stop(self):
if self.running: if self.running:
@ -36,24 +37,21 @@ class HTTPBlobDownloader(object):
def _download_next_blob_hash_for_file(self): def _download_next_blob_hash_for_file(self):
for blob_hash in self.blob_hashes: for blob_hash in self.blob_hashes:
blob = yield self.blob_manager.get_blob(blob_hash) blob = yield self.blob_manager.get_blob(blob_hash)
if not blob.get_is_verified(): if not blob.verified:
self.download_blob(blob) self.download_blob(blob)
defer.returnValue(None) return
self.stop() self.stop()
@defer.inlineCallbacks
def download_blob(self, blob): def download_blob(self, blob):
d = self._download_blob(blob) try:
d.addCallback(self._on_completed_blob) blob_hash = yield self._download_blob(blob)
d.addErrback(self._on_failed)
def _on_completed_blob(self, blob_hash):
if blob_hash: if blob_hash:
log.debug('Mirror completed download for %s', blob_hash) log.debug('Mirror completed download for %s', blob_hash)
self.failures = 0 self.failures = 0
except Exception as exception:
def _on_failed(self, err):
self.failures += 1 self.failures += 1
log.error('Mirror failed downloading: %s', err) log.error('Mirror failed downloading: %s', exception)
if self.failures >= self.max_failures: if self.failures >= self.max_failures:
self.stop() self.stop()
self.failures = 0 self.failures = 0