log unexpected errors, rename task/loop
This commit is contained in:
parent
60969e4817
commit
c4b86454b5
2 changed files with 14 additions and 6 deletions
|
@ -386,7 +386,7 @@ class BackgroundDownloaderComponent(Component):
|
||||||
|
|
||||||
def __init__(self, component_manager):
|
def __init__(self, component_manager):
|
||||||
super().__init__(component_manager)
|
super().__init__(component_manager)
|
||||||
self.task: typing.Optional[asyncio.Task] = None
|
self.background_task: typing.Optional[asyncio.Task] = None
|
||||||
self.download_loop_delay_seconds = 60
|
self.download_loop_delay_seconds = 60
|
||||||
self.ongoing_download: typing.Optional[asyncio.Task] = None
|
self.ongoing_download: typing.Optional[asyncio.Task] = None
|
||||||
self.space_manager: typing.Optional[DiskSpaceManager] = None
|
self.space_manager: typing.Optional[DiskSpaceManager] = None
|
||||||
|
@ -404,11 +404,11 @@ class BackgroundDownloaderComponent(Component):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def get_status(self):
|
async def get_status(self):
|
||||||
return {'running': self.task is not None and not self.task.done(),
|
return {'running': self.background_task is not None and not self.background_task.done(),
|
||||||
'available_free_space_mb': self.space_available,
|
'available_free_space_mb': self.space_available,
|
||||||
'ongoing_download': self.is_busy}
|
'ongoing_download': self.is_busy}
|
||||||
|
|
||||||
async def loop(self):
|
async def download_blobs_in_background(self):
|
||||||
while True:
|
while True:
|
||||||
self.space_available = await self.space_manager.get_free_space_mb(True)
|
self.space_available = await self.space_manager.get_free_space_mb(True)
|
||||||
if not self.is_busy and self.space_available > 10:
|
if not self.is_busy and self.space_available > 10:
|
||||||
|
@ -426,13 +426,13 @@ class BackgroundDownloaderComponent(Component):
|
||||||
self.blob_manager = self.component_manager.get_component(BLOB_COMPONENT)
|
self.blob_manager = self.component_manager.get_component(BLOB_COMPONENT)
|
||||||
storage = self.component_manager.get_component(DATABASE_COMPONENT)
|
storage = self.component_manager.get_component(DATABASE_COMPONENT)
|
||||||
self.background_downloader = BackgroundDownloader(self.conf, storage, self.blob_manager, self.dht_node)
|
self.background_downloader = BackgroundDownloader(self.conf, storage, self.blob_manager, self.dht_node)
|
||||||
self.task = asyncio.create_task(self.loop())
|
self.background_task = asyncio.create_task(self.download_blobs_in_background())
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
if self.ongoing_download and not self.ongoing_download.done():
|
if self.ongoing_download and not self.ongoing_download.done():
|
||||||
self.ongoing_download.cancel()
|
self.ongoing_download.cancel()
|
||||||
if self.task:
|
if self.background_task:
|
||||||
self.task.cancel()
|
self.background_task.cancel()
|
||||||
|
|
||||||
|
|
||||||
class DiskSpaceComponent(Component):
|
class DiskSpaceComponent(Component):
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
from lbry.stream.downloader import StreamDownloader
|
from lbry.stream.downloader import StreamDownloader
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BackgroundDownloader:
|
class BackgroundDownloader:
|
||||||
def __init__(self, conf, storage, blob_manager, dht_node=None):
|
def __init__(self, conf, storage, blob_manager, dht_node=None):
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
|
@ -18,5 +22,9 @@ class BackgroundDownloader:
|
||||||
await downloader.download_stream_blob(blob_info)
|
await downloader.download_stream_blob(blob_info)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
raise
|
||||||
|
except Exception:
|
||||||
|
log.error("Unexpected download error on background downloader")
|
||||||
finally:
|
finally:
|
||||||
downloader.stop()
|
downloader.stop()
|
||||||
|
|
Loading…
Add table
Reference in a new issue