Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

863 followup #870

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions kolibri_explore_plugin/collectionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ def _set_empty_state(self):
self._enqueuing_timestamp = None
self._enqueued_timestamp = None

def from_manifest(self, manifest, user):
def is_state_unset(self):
return (
self._stage == DownloadStage.NOT_STARTED
and self._content_manifest is None
)

def start(self, manifest, user):
"""Start downloading a collection manifest."""
if self._stage != DownloadStage.NOT_STARTED:
raise DownloadError("A download has already started. Can't start")
Expand All @@ -265,6 +271,12 @@ def from_state(self, state):
self._tasks_completed = state["tasks_completed"]
self._tasks_previously_completed = state["tasks_previously_completed"]

logger.info(
f"Download state loaded for grade={grade} name={name}, "
+ f"stage={stage_name}"
)
logger.debug(f"Loaded download state: {state}")

def cancel(self):
if self._current_job_id is not None:
job_storage.cancel(self._current_job_id)
Expand Down Expand Up @@ -646,7 +658,7 @@ def start_download(request):

# Init the download manager and start downloading
try:
_collection_download_manager.from_manifest(manifest, request.user)
_collection_download_manager.start(manifest, request.user)
logger.info(f"Download started for grade={grade} name={name}")
except DownloadError as err:
raise APIException(err)
Expand Down Expand Up @@ -733,5 +745,13 @@ def cancel_download(request):
@api_view(["GET"])
def get_download_status(request):
"""Return the download status."""

saved_state = request.session.get("COLLECTIONS_STATE")
if (
_collection_download_manager.is_state_unset()
and saved_state is not None
):
_collection_download_manager.from_state(saved_state)

status = _collection_download_manager.get_status()
return Response({"status": status})