add _download_failed errback

This commit is contained in:
Jack Robison 2017-09-28 13:53:12 -04:00
parent 82a2805aaf
commit 9fd60c823f
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF

View file

@ -635,18 +635,25 @@ class Daemon(AuthJSONRPCServer):
defer.returnValue(report) defer.returnValue(report)
@defer.inlineCallbacks @defer.inlineCallbacks
def _download_finished(self, download_id, name, claim_dict): def _download_name(self, name, claim_dict, claim_id, timeout=None, file_name=None):
report = yield self._get_stream_analytics_report(claim_dict)
self.analytics_manager.send_download_finished(download_id, name, report, claim_dict)
@defer.inlineCallbacks
def _download_name(self, name, claim_dict, claim_id, timeout=None, file_name=None,
delete_on_timeout=True):
""" """
Add a lbry file to the file manager, start the download, and return the new lbry file. Add a lbry file to the file manager, start the download, and return the new lbry file.
If it already exists in the file manager, return the existing lbry file If it already exists in the file manager, return the existing lbry file
""" """
@defer.inlineCallbacks
def _download_finished(download_id, name, claim_dict):
log.info("Finished: %s", name)
report = yield self._get_stream_analytics_report(claim_dict)
self.analytics_manager.send_download_finished(download_id, name, report, claim_dict)
@defer.inlineCallbacks
def _download_failed(error, download_id, name, claim_dict):
log.warning("Failed %s: %s", name, error)
report = yield self._get_stream_analytics_report(claim_dict)
self.analytics_manager.send_download_errored(error, download_id, name, claim_dict,
report)
if claim_id in self.streams: if claim_id in self.streams:
downloader = self.streams[claim_id] downloader = self.streams[claim_id]
result = yield downloader.finished_deferred result = yield downloader.finished_deferred
@ -662,18 +669,20 @@ class Daemon(AuthJSONRPCServer):
file_name) file_name)
try: try:
lbry_file, finished_deferred = yield self.streams[claim_id].start(claim_dict, name) lbry_file, finished_deferred = yield self.streams[claim_id].start(claim_dict, name)
finished_deferred.addCallback(lambda _: self._download_finished(download_id, name, finished_deferred.addCallbacks(lambda _: _download_finished(download_id, name,
claim_dict),
lambda e: _download_failed(e, download_id, name,
claim_dict)) claim_dict))
result = yield self._get_lbry_file_dict(lbry_file, full_status=True) result = yield self._get_lbry_file_dict(lbry_file, full_status=True)
except (DownloadDataTimeout, DownloadSDTimeout) as err: except Exception as err:
if isinstance(err, (DownloadDataTimeout, DownloadSDTimeout)):
log.warning('Failed to get %s (%s)', name, err) log.warning('Failed to get %s (%s)', name, err)
report = yield self._get_stream_analytics_report(claim_dict) else:
if isinstance(err, DownloadDataTimeout) and delete_on_timeout: log.error('Failed to get %s (%s)', name, err)
yield self.lbry_file_manager.delete_lbry_file(self.streams[claim_id].downloader) if self.streams[claim_id].downloader:
elif self.streams[claim_id].downloader:
yield self.streams[claim_id].downloader.stop(err) yield self.streams[claim_id].downloader.stop(err)
self.analytics_manager.send_download_errored(err, download_id, name, claim_dict, yield _download_failed(err, download_id, name, claim_dict)
report)
result = {'error': err.message} result = {'error': err.message}
del self.streams[claim_id] del self.streams[claim_id]
defer.returnValue(result) defer.returnValue(result)