diff --git a/lbry/blob/disk_space_manager.py b/lbry/blob/disk_space_manager.py index 7c48e5e75..d6af70239 100644 --- a/lbry/blob/disk_space_manager.py +++ b/lbry/blob/disk_space_manager.py @@ -15,9 +15,9 @@ class DiskSpaceManager: self.task = None self.analytics = analytics - async def get_free_space_bytes(self, is_network_blob=False): + async def get_free_space_mb(self, is_network_blob=False): limit_mb = self.config.network_storage_limit if is_network_blob else self.config.blob_storage_limit - return max(0, limit_mb*1024*1024 - (await self.get_space_used_mb(is_network_blob))) + return max(0, limit_mb - (await self.get_space_used_mb(is_network_blob))) async def get_space_used_bytes(self, is_network_blob=False): return await self.db.get_stored_blob_disk_usage(is_network_blob=is_network_blob) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index 17ef80695..61aaa9c51 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -403,11 +403,12 @@ class BackgroundDownloaderComponent(Component): async def get_status(self): return {'running': self.task is not None and not self.task.done(), + 'available_free_space': await self.space_manager.get_free_space_mb(True), 'ongoing_download': self.is_busy} async def loop(self): while True: - if not self.is_busy and await self.space_manager.get_free_space_bytes(True) > 0: + if not self.is_busy and await self.space_manager.get_free_space_mb(True) > 10: blob_hash = self.dht_node.last_requested_blob_hash if blob_hash: self.ongoing_download = asyncio.create_task(self.background_downloader.download_blobs(blob_hash)) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 03572dcec..9be8da26b 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -629,6 +629,8 @@ class TestProactiveDownloaderComponent(CommandTestCase): await self.assertBlobs(content2) self.assertEqual('0', (await self.status())['disk_space']['space_used']) self.assertEqual('16', (await self.status())['disk_space']['network_seeding_space_used']) + self.daemon.conf.network_storage_limit = 100 + self.assertEqual(84, (await self.status())['background_downloader']['available_free_space']) # tests that an attempt to download something that isn't a sd blob will download the single blob and stop blobs = await self.get_blobs_from_sd_blob(self.reflector.blob_manager.get_blob(content1))