Retrying failed downloads when Retry button is used.

This commit is contained in:
Roland 2026-04-05 12:10:15 -06:00
parent c5a00b0de5
commit 3fc6c1f7f1
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 36 additions and 2 deletions

View file

@ -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]:

View file

@ -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."""