From d58c8559fc9125574989f52a5a7d19dd5303db4f Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 23 Jul 2020 21:39:13 +0200 Subject: [PATCH] Long-running async tasks: Expose running state --- src/pretix/base/views/tasks.py | 8 ++++- src/pretix/static/pretixbase/js/asynctask.js | 32 ++++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/pretix/base/views/tasks.py b/src/pretix/base/views/tasks.py index 9c5825dbc0..76f4678090 100644 --- a/src/pretix/base/views/tasks.py +++ b/src/pretix/base/views/tasks.py @@ -77,7 +77,8 @@ class AsyncAction: data = self._ajax_response_data() data.update({ 'async_id': res.id, - 'ready': ready + 'ready': ready, + 'started': False, }) if ready: if res.successful() and not isinstance(res.info, Exception): @@ -102,8 +103,13 @@ class AsyncAction: }) elif res.state == 'PROGRESS': data.update({ + 'started': True, 'percentage': res.result.get('value', 0) }) + elif res.state == 'STARTED': + data.update({ + 'started': True, + }) return data def get_result(self, request): diff --git a/src/pretix/static/pretixbase/js/asynctask.js b/src/pretix/static/pretixbase/js/asynctask.js index 86b85033dd..dbdff3c888 100644 --- a/src/pretix/static/pretixbase/js/asynctask.js +++ b/src/pretix/static/pretixbase/js/asynctask.js @@ -38,11 +38,17 @@ function async_task_check_callback(data, jqXHR, status) { async_task_timeout = window.setTimeout(async_task_check, 250); if (async_task_is_long) { - $("#loadingmodal p.status").text(gettext( - 'Your request has been queued on the server and will now be ' + - 'processed. Depending on the size of your event, this might take up to a ' + - 'few minutes.' - )); + if (data.started) { + $("#loadingmodal p.status").text(gettext( + 'Your request is currently being processed. Depending on the size of your event, this might take up to ' + + 'a few minutes.' + )); + } else { + $("#loadingmodal p.status").text(gettext( + 'Your request has been queued on the server and will soon be ' + + 'processed.' + )); + } } else { $("#loadingmodal p.status").text(gettext( 'Your request arrived on the server but we still wait for it to be ' + @@ -105,11 +111,17 @@ function async_task_callback(data, jqXHR, status) { async_task_timeout = window.setTimeout(async_task_check, 100); if (async_task_is_long) { - $("#loadingmodal p.status").text(gettext( - 'Your request has been queued on the server and will now be ' + - 'processed. Depending on the size of your event, this might take up to a ' + - 'few minutes.' - )); + if (data.started) { + $("#loadingmodal p.status").text(gettext( + 'Your request is currently being processed. Depending on the size of your event, this might take up to ' + + 'a few minutes.' + )); + } else { + $("#loadingmodal p.status").text(gettext( + 'Your request has been queued on the server and will soon be ' + + 'processed.' + )); + } } else { $("#loadingmodal p.status").text(gettext( 'Your request arrived on the server but we still wait for it to be ' +