From 3fc6c1f7f1bbd93d07c738df50e5bcc185a67eab Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 5 Apr 2026 12:10:15 -0600 Subject: [PATCH] Retrying failed downloads when Retry button is used. --- wrolpi/downloader.py | 4 ++-- wrolpi/test/test_downloader.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index d365b0b5..904b509e 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -990,9 +990,9 @@ class DownloadManager: """ with get_db_curs(commit=True) as curs: if reset_attempts: - stmt = "UPDATE download SET status='new', attempts=0 WHERE status='pending' OR status='deferred'" + stmt = "UPDATE download SET status='new', attempts=0 WHERE status='pending' OR status='deferred' OR status='failed'" else: - stmt = "UPDATE download SET status='new' WHERE status='pending' OR status='deferred'" + stmt = "UPDATE download SET status='new' WHERE status='pending' OR status='deferred' OR status='failed'" curs.execute(stmt) def get_new_downloads(self, session: Session) -> Generator[Download, None, None]: diff --git a/wrolpi/test/test_downloader.py b/wrolpi/test/test_downloader.py index c535df1e..2721efc8 100644 --- a/wrolpi/test/test_downloader.py +++ b/wrolpi/test/test_downloader.py @@ -889,6 +889,40 @@ async def test_batch_delete_downloads(test_session, test_download_manager, test_ assert deleted_ids == [] +@pytest.mark.asyncio +async def test_retry_downloads_includes_failed(test_session, test_download_manager, test_downloader): + """Test that retry_downloads retries failed, pending, and deferred downloads.""" + d1 = test_download_manager.create_download(test_session, 'https://example.com/1', test_downloader.name) + d2 = test_download_manager.create_download(test_session, 'https://example.com/2', test_downloader.name) + d3 = test_download_manager.create_download(test_session, 'https://example.com/3', test_downloader.name) + d4 = test_download_manager.create_download(test_session, 'https://example.com/4', test_downloader.name) + + # Set different statuses + d1.fail() + d1.attempts = 5 + d2.defer() + d2.attempts = 3 + d3.status = 'pending' + d3.attempts = 1 + d4.complete() # completed download should not be retried + test_session.commit() + + test_download_manager.retry_downloads(reset_attempts=True) + + test_session.refresh(d1) + test_session.refresh(d2) + test_session.refresh(d3) + test_session.refresh(d4) + + assert d1.status == 'new' + assert d1.attempts == 0 + assert d2.status == 'new' + assert d2.attempts == 0 + assert d3.status == 'new' + assert d3.attempts == 0 + assert d4.status == 'complete' # unchanged + + @pytest.mark.asyncio async def test_batch_retry_downloads(test_session, test_download_manager, test_downloader): """Test retrying specific downloads by their IDs."""