Repository: Cadair/parfive

Issue:
Way to find number of queued files
It would be nice if `Downloader` could have an attribute that is the number of files queued for download. (just starting to play with this for HelioPy)

Discussion:

Patch:
diff --git a/parfive/downloader.py b/parfive/downloader.py
index 90e7f52..0c13d2d 100644
--- a/parfive/downloader.py
+++ b/parfive/downloader.py
@@ -89,6 +89,14 @@ class Downloader:
             self.http_tokens.put_nowait(Token(i + 1))
             self.ftp_tokens.put_nowait(Token(i + 1))
 
+    @property
+    def queued_downloads(self):
+        """
+        The total number of files already queued for download.
+        """
+
+        return self.http_queue.qsize() + self.ftp_queue.qsize()
+
     def enqueue_file(self, url, path=None, filename=None, overwrite=None, **kwargs):
         """
         Add a file to the download queue.


Test patch:
diff --git a/parfive/tests/test_downloader.py b/parfive/tests/test_downloader.py
index c8c07ac..e134c79 100644
--- a/parfive/tests/test_downloader.py
+++ b/parfive/tests/test_downloader.py
@@ -26,6 +26,9 @@ def test_download(event_loop, httpserver, tmpdir):
     dl = Downloader(loop=event_loop)
 
     dl.enqueue_file(httpserver.url, path=Path(tmpdir))
+
+    assert dl.queued_downloads == 1
+
     f = dl.download()
 
     assert len(f) == 1
@@ -314,6 +317,9 @@ def test_ftp_http(tmpdir, httpserver):
     dl.enqueue_file(httpserver.url, path=tmpdir)
     dl.enqueue_file("http://noaurl.notadomain/noafile", path=tmpdir)
 
+
+    assert dl.queued_downloads == 6
+
     f = dl.download()
     assert len(f) == 2
     assert len(f.errors) == 4