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

Use Kolibri's FileDownloader #729

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ extend-exclude =
build/,
static/,
dist/,
node_modules/,
kolibri_explore_plugin/vendor/
node_modules/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: (\.git/|\.tox/|\.venv/|build/|static/|dist/|node_modules/|kolibri_explore_plugin/vendor/)
exclude: (\.git/|\.tox/|\.venv/|build/|static/|dist/|node_modules/)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
Expand Down
2 changes: 1 addition & 1 deletion kolibri_explore_plugin/collectionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from kolibri.core.content.errors import InsufficientStorageSpaceError
from kolibri.core.content.models import ChannelMetadata
from kolibri.core.content.tasks import remotechannelimport
from kolibri.core.content.tasks import remotecontentimport
from kolibri.core.content.utils.content_manifest import ContentManifest
from kolibri.core.content.utils.content_manifest import (
ContentManifestParseError,
Expand All @@ -24,7 +25,6 @@
from .tasks import applyexternaltags
from .tasks import BACKGROUND_QUEUE
from .tasks import QUEUE
from .tasks import remotecontentimport

logger = logging.getLogger(__name__)

Expand Down
76 changes: 0 additions & 76 deletions kolibri_explore_plugin/tasks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import logging

from django.core.management import call_command
from kolibri.core.content.tasks import get_status as get_content_task_status
from kolibri.core.content.tasks import RemoteChannelResourcesImportValidator
from kolibri.core.content.utils.paths import get_content_storage_remote_url
from kolibri.core.content.utils.resource_import import (
RemoteChannelResourceImportManager,
)
from kolibri.core.content.utils.resource_import import (
RemoteChannelUpdateManager,
)
from kolibri.core.content.utils.resource_import import (
RemoteResourceImportManagerBase,
)
from kolibri.core.serializers import HexOnlyUUIDField
from kolibri.core.tasks.decorators import register_task
from kolibri.core.tasks.job import State
Expand All @@ -22,8 +10,6 @@
from rest_framework.serializers import CharField
from rest_framework.serializers import ListField

from .vendor.file_transfer import FileDownload

logger = logging.getLogger(__name__)

QUEUE = "content"
Expand Down Expand Up @@ -58,68 +44,6 @@ def applyexternaltags(node_id, tags=None):
call_command("applyexternaltags", node_id, tags=tags)


# Local remote resource import overrides to use vendored FileDownload.
class ExploreRemoteResourceImportManagerBase(RemoteResourceImportManagerBase):
def create_file_transfer(self, f, filename, dest):
url = get_content_storage_remote_url(filename, baseurl=self.baseurl)
return FileDownload(
url,
dest,
f["id"],
session=self.session,
cancel_check=self.is_cancelled,
timeout=self.timeout,
)


class ExploreRemoteChannelResourceImportManager(
ExploreRemoteResourceImportManagerBase, RemoteChannelResourceImportManager
):
pass


class ExploreRemoteChannelUpdateManager(
ExploreRemoteResourceImportManagerBase, RemoteChannelUpdateManager
):
pass


@register_task(
validator=RemoteChannelResourcesImportValidator,
track_progress=True,
cancellable=True,
permission_classes=[CanManageContent],
queue=QUEUE,
long_running=True,
status_fn=get_content_task_status,
)
def remotecontentimport(
channel_id,
baseurl=None,
peer_id=None,
node_ids=None,
exclude_node_ids=None,
update=False,
fail_on_error=False,
all_thumbnails=False,
):
manager_class = (
ExploreRemoteChannelUpdateManager
if update
else ExploreRemoteChannelResourceImportManager
)
manager = manager_class(
channel_id,
baseurl=baseurl,
peer_id=peer_id,
node_ids=node_ids,
exclude_node_ids=exclude_node_ids,
fail_on_error=fail_on_error,
all_thumbnails=all_thumbnails,
)
manager.run()


def restart_failed_background_jobs():
for job in job_storage.get_all_jobs(queue=BACKGROUND_QUEUE):
if job.state == State.FAILED:
Expand Down
Empty file.
Loading