retry the get call three times before failing
This commit is contained in:
parent
854dea797e
commit
3dc1a523cf
2 changed files with 39 additions and 26 deletions
|
@ -1550,7 +1550,12 @@ class Daemon(AuthJSONRPCServer):
|
||||||
|
|
||||||
download_id = utils.random_string()
|
download_id = utils.random_string()
|
||||||
self.analytics_manager.send_download_started(download_id, name, stream_info)
|
self.analytics_manager.send_download_started(download_id, name, stream_info)
|
||||||
|
tries = 1
|
||||||
|
max_tries = 3
|
||||||
|
while tries <= max_tries:
|
||||||
try:
|
try:
|
||||||
|
log.info(
|
||||||
|
'Making try %s / %s to start download of %s', tries, max_tries, params.name)
|
||||||
sd_hash, file_path = yield self._download_name(
|
sd_hash, file_path = yield self._download_name(
|
||||||
name=params.name,
|
name=params.name,
|
||||||
timeout=params.timeout,
|
timeout=params.timeout,
|
||||||
|
@ -1559,11 +1564,14 @@ class Daemon(AuthJSONRPCServer):
|
||||||
file_name=params.file_name,
|
file_name=params.file_name,
|
||||||
wait_for_write=params.wait_for_write
|
wait_for_write=params.wait_for_write
|
||||||
)
|
)
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.analytics_manager.send_download_errored(download_id, name, stream_info)
|
|
||||||
log.exception('Failed to get %s', params.name)
|
log.exception('Failed to get %s', params.name)
|
||||||
|
if tries == max_tries:
|
||||||
|
self.analytics_manager.send_download_errored(download_id, name, stream_info)
|
||||||
response = yield self._render_response(str(e))
|
response = yield self._render_response(str(e))
|
||||||
else:
|
defer.returnValue(response)
|
||||||
|
tries += 1
|
||||||
# TODO: should stream_hash key be changed to sd_hash?
|
# TODO: should stream_hash key be changed to sd_hash?
|
||||||
message = {
|
message = {
|
||||||
'stream_hash': params.sd_hash if params.stream_info else sd_hash,
|
'stream_hash': params.sd_hash if params.stream_info else sd_hash,
|
||||||
|
|
|
@ -72,7 +72,7 @@ class GetStream(object):
|
||||||
self.finished.callback((True, self.sd_hash, self.download_path))
|
self.finished.callback((True, self.sd_hash, self.download_path))
|
||||||
|
|
||||||
elif self.timeout_counter >= self.timeout:
|
elif self.timeout_counter >= self.timeout:
|
||||||
log.info("Timeout downloading lbry://%s" % self.resolved_name)
|
log.info("Timeout downloading lbry://%s", self.resolved_name)
|
||||||
self.checker.stop()
|
self.checker.stop()
|
||||||
self._d.cancel()
|
self._d.cancel()
|
||||||
self.code = STREAM_STAGES[4]
|
self.code = STREAM_STAGES[4]
|
||||||
|
@ -86,6 +86,11 @@ class GetStream(object):
|
||||||
|
|
||||||
def start(self, stream_info, name):
|
def start(self, stream_info, name):
|
||||||
def _cancel(err):
|
def _cancel(err):
|
||||||
|
# this callback sequence gets cancelled in check_status if
|
||||||
|
# it takes too long when that happens, we want the logic
|
||||||
|
# to live in check_status
|
||||||
|
if err.check(defer.CancelledError):
|
||||||
|
return
|
||||||
if self.checker:
|
if self.checker:
|
||||||
self.checker.stop()
|
self.checker.stop()
|
||||||
self.finished.errback(err)
|
self.finished.errback(err)
|
||||||
|
|
Loading…
Reference in a new issue