Skip to content

Commit

Permalink
Download: Add a stage to import all channels
Browse files Browse the repository at this point in the history
After the `APPLYING_EXTERNAL_TAGS` stage, the DownloadManager will enter
a new `IMPORTING_EXTRA_CHANNELS` stage. In this stage, it should
download metadata for any channels which are listed in another content
collection.

Issue #548
  • Loading branch information
dylanmccall committed Jun 8, 2023
1 parent 1e8cf9e commit 187866a
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions kolibri_explore_plugin/collectionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def __init__(self):
self.available = None
super().__init__()

def get_extra_channel_ids(self):
all_channel_ids = _get_channel_ids_for_all_content_manifests()
return all_channel_ids.difference(self.get_channel_ids())

def read_from_static_collection(self, grade, name, validate=False):
self.grade = grade
self.name = name
Expand Down Expand Up @@ -112,22 +116,20 @@ def get_channelimport_tasks(self):
For all the channels in this content manifest.
"""
tasks = []
return [
_build_remotechannelimport_task(channel_id)
for channel_id in self.get_channel_ids()
]

for channel_id in self.get_channel_ids():
tasks.append(
{
"task": "remotechannelimport",
"params": {
"channel_id": channel_id,
# FIXME: The channel_name is needed
# since commit b53d7baa
"channel_name": "foo",
},
}
)
def get_extra_channelimport_tasks(self):
"""Return a serializable object to create extra channelimport tasks
return tasks
For all channels featured in Endless Key content manifests.
"""
return [
_build_remotechannelimport_task(channel_id)
for channel_id in self.get_extra_channel_ids()
]

def get_contentimport_tasks(self):
"""Return a serializable object to create contentimport tasks
Expand Down Expand Up @@ -227,6 +229,7 @@ class DownloadStage(IntEnum):
IMPORTING_CHANNELS = auto()
IMPORTING_CONTENT = auto()
APPLYING_EXTERNAL_TAGS = auto()
IMPORTING_EXTRA_CHANNELS = auto()
COMPLETED = auto()


Expand Down Expand Up @@ -421,7 +424,10 @@ def get_status(self):
+ progress_per_channel * current_job_factor
)

elif self._stage == DownloadStage.COMPLETED:
elif self._stage in (
DownloadStage.IMPORTING_EXTRA_CHANNELS,
DownloadStage.COMPLETED,
):
progress = 1

return {
Expand Down Expand Up @@ -476,6 +482,8 @@ def _set_next_stage(self):
tasks = self._content_manifest.get_contentimport_tasks()
elif self._stage == DownloadStage.APPLYING_EXTERNAL_TAGS:
tasks = self._content_manifest.get_applyexternaltags_tasks()
elif self._stage == DownloadStage.IMPORTING_EXTRA_CHANNELS:
tasks = self._content_manifest.get_extra_channelimport_tasks()

self._tasks_pending = tasks
self._tasks_previously_completed.extend(self._tasks_completed)
Expand Down Expand Up @@ -514,6 +522,18 @@ def _call_task(task, user, **params):
return job_id


def _build_remotechannelimport_task(channel_id):
return {
"task": "remotechannelimport",
"params": {
"channel_id": channel_id,
# FIXME: The channel_name is needed
# since commit b53d7baa
"channel_name": "foo",
},
}


_content_manifests = []
_content_manifests_by_grade_name = {}
_collection_download_manager = CollectionDownloadManager()
Expand Down Expand Up @@ -573,6 +593,13 @@ def _get_collections_info_by_grade_name(grade, name):
}


def _get_channel_ids_for_all_content_manifests():
channel_ids = set()
for content_manifest in _content_manifests:
channel_ids.update(content_manifest.get_channel_ids())
return channel_ids


@api_view(["GET"])
def get_collection_info(request):
"""Return the collection metadata and availability."""
Expand Down

0 comments on commit 187866a

Please sign in to comment.