mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 10:51:36 -04:00
Retrying failed downloads when Retry button is used.
This commit is contained in:
parent
c5a00b0de5
commit
3fc6c1f7f1
2 changed files with 36 additions and 2 deletions
|
|
@ -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]:
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue