Created download retry button.

This commit is contained in:
Roland 2024-05-08 17:02:27 -06:00
parent bd16ad1e0c
commit 63381c1d77
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 56 additions and 31 deletions

View file

@ -786,6 +786,20 @@ export async function deleteOnceDownloads() {
}
}
export async function retryOnceDownloads() {
let response = await apiPost(`${API_URI}/download/retry_once`);
if (response.status === 204) {
return null
} else {
toast({
type: 'error',
title: 'Error!',
description: 'Could not retry once downloads! See server logs.',
time: 5000,
});
}
}
export async function getStatistics() {
let response = await apiGet(`${API_URI}/statistics`);
if (response.status === 200) {

View file

@ -1537,10 +1537,6 @@ export function useAPIButton(
</>
}
button = <>
{button}
</>
return {button, ref}
}

View file

@ -1,11 +1,11 @@
import React from "react";
import {
clearCompletedDownloads,
clearFailedDownloads,
deleteDownload,
deleteOnceDownloads,
killDownload,
restartDownload
restartDownload,
retryOnceDownloads
} from "../../api";
import {Link} from "react-router-dom";
import {
@ -33,7 +33,7 @@ import {Button, Header, Modal, ModalActions, ModalContent, ModalHeader, Placehol
import {useDownloads} from "../../hooks/customHooks";
import {toast} from "react-semantic-toasts-2";
function ClearCompleteDownloads({callback}) {
function ClearDownloadsButton({callback}) {
async function localClearDownloads() {
try {
await clearCompletedDownloads();
@ -49,14 +49,14 @@ function ClearCompleteDownloads({callback}) {
onClick={localClearDownloads}
color='violet'
obeyWROLMode={true}
>Clear Completed</APIButton>
>Clear</APIButton>
</>
}
function ClearFailedDownloads({callback}) {
async function localDeleteFailed() {
function RetryDownloadsButton({callback}) {
async function localRetryOnce() {
try {
await clearFailedDownloads();
await retryOnceDownloads();
} finally {
if (callback) {
callback()
@ -65,17 +65,13 @@ function ClearFailedDownloads({callback}) {
}
return <APIButton
color='yellow'
onClick={localDeleteFailed}
confirmContent='Are you sure you want to delete failed downloads? They will not be retried.'
confirmButton='Delete'
color='green'
onClick={localRetryOnce}
obeyWROLMode={true}
>
Clear Failed
</APIButton>
>Retry</APIButton>
}
function DeleteOnceDownloads({callback}) {
function DeleteOnceDownloadsButton({callback}) {
async function localDeleteOnce() {
try {
await deleteOnceDownloads();
@ -89,12 +85,10 @@ function DeleteOnceDownloads({callback}) {
return <APIButton
color='red'
onClick={localDeleteOnce}
confirmContent='Are you sure you want to delete all downloads? They may be retried!'
confirmContent='Are you sure you want to delete all downloads? Some may be retried!'
confirmButton='Delete'
obeyWROLMode={true}
>
Delete All
</APIButton>
>Delete</APIButton>
}
class RecurringDownloadRow extends React.Component {
@ -333,9 +327,9 @@ export function OnceDownloadsTable({downloads, fetchDownloads}) {
<TableFooter>
<TableRow>
<TableHeaderCell colSpan={3}>
<ClearCompleteDownloads callback={fetchDownloads}/>
<ClearFailedDownloads callback={fetchDownloads}/>
<DeleteOnceDownloads callback={fetchDownloads}/>
<ClearDownloadsButton callback={fetchDownloads}/>
<RetryDownloadsButton callback={fetchDownloads}/>
<DeleteOnceDownloadsButton callback={fetchDownloads}/>
</TableHeaderCell>
</TableRow>
</TableFooter>

View file

@ -237,7 +237,7 @@ async def start_single_tasks(app: Sanic):
if flags.refresh_complete.is_set():
# Set all downloads to new.
download_manager.reset_downloads()
download_manager.retry_downloads()
# Hotspot/throttle are not supported in Docker containers.
if not DOCKERIZED and get_wrolpi_config().hotspot_on_startup:

View file

@ -593,11 +593,13 @@ class DownloadManager:
raise TimeoutError('Downloads never finished!')
@staticmethod
def reset_downloads():
def retry_downloads():
"""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'")
api_app.add_task(save_downloads_config())
DOWNLOAD_SORT = (
DownloadStatus.pending,
DownloadStatus.failed,

View file

@ -329,6 +329,13 @@ async def clear_failed(_: Request):
return response.empty()
@api_bp.post('/download/retry_once')
@openapi.description('Retry failed once-downloads')
async def retry_once(_: Request):
download_manager.retry_downloads()
return response.empty()
@api_bp.post('/download/delete_once')
@openapi.description('Delete all once downloads')
async def delete_once(_: Request):

View file

@ -14,7 +14,7 @@ def assert_db(session: Session, name: str, expected: bool):
assert getattr(f, name) is expected
def test_flags(test_session, flags_lock):
def test_flags(test_async_client, test_session, flags_lock):
"""DB flags can be saved."""
assert flags.refresh_complete.is_set() is False
assert flags.get_flags() == []
@ -28,7 +28,7 @@ def test_flags(test_session, flags_lock):
assert flags.get_flags() == []
def test_flags_with(flags_lock):
def test_flags_with(test_async_client, flags_lock):
"""A Flag can be used with `with` context."""
assert flags.refreshing.is_set() is False, 'Flag should not be set by default'
assert flags.get_flags() == []
@ -48,7 +48,7 @@ def test_flags_with(flags_lock):
@pytest.mark.asyncio
async def test_flag_wait_for(flags_lock):
async def test_flag_wait_for(test_async_client, flags_lock):
"""Wait for throws an error when waiting exceeds timeout."""
with pytest.raises(TimeoutError):
async with flags.refreshing.wait_for(timeout=1):

View file

@ -348,6 +348,17 @@ async def test_clear_downloads(test_session, test_async_client, test_config, tes
# Failed once-downloads will not be downloaded again.
assert get_download_manager_config().skip_urls == ['https://example.com/5', ]
# Downloads can be retried.
request, response = await test_async_client.post('/api/download/retry_once')
assert response.status_code == HTTPStatus.NO_CONTENT
request, response = await test_async_client.get('/api/download')
once_downloads = [
{'url': 'https://example.com/2', 'status': 'new'},
{'url': 'https://example.com/3', 'status': 'new'},
{'url': 'https://example.com/4', 'status': 'new'},
]
check_downloads(response, once_downloads, recurring_downloads, status_code=HTTPStatus.OK)
# "Delete All" button deletes all once-downloads.
request, response = await test_async_client.post('/api/download/delete_once')
assert response.status_code == HTTPStatus.NO_CONTENT
@ -592,6 +603,7 @@ async def test_search_file_estimates(test_session, test_async_client, archive_fa
@pytest.mark.asyncio
async def test_external_error(test_async_client):
"""A non-SanicException error is handled as an Internal Server Error."""
@test_async_client.sanic_app.get('/error')
async def error(_: Request):
raise RuntimeError('Oh no!')