mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Retry button resets attempts.
This commit is contained in:
parent
2fabae9cb8
commit
a25b8373c9
3 changed files with 35 additions and 3 deletions
|
|
@ -121,6 +121,7 @@ class Download(ModelHelper, Base): # noqa
|
|||
|
||||
def __json__(self) -> dict:
|
||||
d = dict(
|
||||
attempts=self.attempts,
|
||||
channel_id=self.channel_id,
|
||||
downloader=self.downloader,
|
||||
frequency=self.frequency,
|
||||
|
|
@ -654,10 +655,13 @@ class DownloadManager:
|
|||
raise TimeoutError('Downloads never finished!')
|
||||
|
||||
@staticmethod
|
||||
def retry_downloads():
|
||||
def retry_downloads(reset_attempts: bool = False):
|
||||
"""Set any incomplete Downloads to `new` so they will be retried."""
|
||||
with get_db_curs(commit=True) as curs:
|
||||
curs.execute("UPDATE download SET status='new' WHERE status='pending' OR status='deferred'")
|
||||
if reset_attempts:
|
||||
curs.execute("UPDATE download SET status='new', attempts=0 WHERE status='pending' OR status='deferred'")
|
||||
else:
|
||||
curs.execute("UPDATE download SET status='new' WHERE status='pending' OR status='deferred'")
|
||||
|
||||
save_downloads_config.activate_switch()
|
||||
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ async def clear_failed(_: Request):
|
|||
@api_bp.post('/download/retry_once')
|
||||
@openapi.description('Retry failed once-downloads')
|
||||
async def retry_once(_: Request):
|
||||
download_manager.retry_downloads()
|
||||
download_manager.retry_downloads(reset_attempts=True)
|
||||
return response.empty()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -375,6 +375,34 @@ async def test_clear_downloads(test_session, async_client, test_wrolpi_config, t
|
|||
assert get_download_manager_config().skip_urls == ['https://example.com/5', ]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_downloads(test_session, async_client, test_wrolpi_config, assert_downloads):
|
||||
"""Downloads that are pending or deferred can be retried, and their attempts reset."""
|
||||
d1 = Download(url='https://example.com/1', status='complete', attempts=1)
|
||||
d2 = Download(url='https://example.com/2', status='pending', attempts=1)
|
||||
d3 = Download(url='https://example.com/3', status='deferred', attempts=1)
|
||||
d4 = Download(url='https://example.com/4', status='new', attempts=1)
|
||||
d5 = Download(url='https://example.com/5', status='failed', attempts=1)
|
||||
d6 = Download(url='https://example.com/6', status='failed', frequency=60, attempts=1)
|
||||
d7 = Download(url='https://example.com/7', status='complete', frequency=60, attempts=1)
|
||||
test_session.add_all([d1, d2, d3, d4, d5, d6, d7])
|
||||
test_session.commit()
|
||||
|
||||
# Retry all once-downloads.
|
||||
request, response = await async_client.post('/api/download/retry_once')
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
assert_downloads([
|
||||
dict(url='https://example.com/1', status='complete', attempts=1), # complete is not retried.
|
||||
dict(url='https://example.com/2', status='new', attempts=0), # pending is retried.
|
||||
dict(url='https://example.com/3', status='new', attempts=0), # deferred is retried.
|
||||
dict(url='https://example.com/4', status='new', attempts=1), # new does not need to be retried.
|
||||
dict(url='https://example.com/5', status='failed', attempts=1), # failed has been given up on.
|
||||
dict(url='https://example.com/6', status='failed', frequency=60, attempts=1,), # recurring is always retried.
|
||||
dict(url='https://example.com/7', status='complete', frequency=60, attempts=1), # recurring is always retried.
|
||||
])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_status(async_client, test_session):
|
||||
"""Get the server status information."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue