Skip to content

Commit

Permalink
Override remotecontentimport task priority to high
Browse files Browse the repository at this point in the history
When we enqueue the `remotecontentimport` task from
`CollectionDownloadManager`, we can specify the priority of the jobs as
high. However, when a user initiates a content download from the
frontend using the tasks API, that's not possible. Since the upstream
default priority is regular, it can get blocked behind any other queued
tasks such as the background thumbnail downloads.

This adds a copy of upstream's `remotecontentimport` with the default
priority set to high and arranges for it to be used throughout the
plugin.

Helps: #739
  • Loading branch information
dbnicholson authored and dylanmccall committed Aug 17, 2023
1 parent b2eb8fc commit 5017480
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TaskStatuses, TaskTypes } from 'kolibri.utils.syncTaskUtils';
import { TaskStatuses } from 'kolibri.utils.syncTaskUtils';
import { constants } from 'ek-components';
import { TaskResource } from 'kolibri.resources';
import store from 'kolibri.coreVue.vuex.store';
Expand Down Expand Up @@ -48,7 +48,7 @@ export function startContentDownload(channelId, contentId) {
channel_id: channelId,
channel_name: 'foo',
node_ids: [contentId],
type: TaskTypes.REMOTECONTENTIMPORT,
type: 'kolibri_explore_plugin.tasks.remotecontentimport',
};

return TaskResource.startTask(taskParams)
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,7 +8,6 @@
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 @@ -25,6 +24,7 @@
from .tasks import applyexternaltags
from .tasks import BACKGROUND_QUEUE
from .tasks import QUEUE
from .tasks import remotecontentimport

logger = logging.getLogger(__name__)

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

from django.core.management import call_command
from kolibri.core.content import tasks as content_tasks
from kolibri.core.serializers import HexOnlyUUIDField
from kolibri.core.tasks.decorators import register_task
from kolibri.core.tasks.job import Priority
from kolibri.core.tasks.job import State
from kolibri.core.tasks.main import job_storage
from kolibri.core.tasks.permissions import CanManageContent
Expand Down Expand Up @@ -44,6 +46,22 @@ def applyexternaltags(node_id, tags=None):
call_command("applyexternaltags", node_id, tags=tags)


# This is a duplicate of the upstream remotecontentimport task with the
# priority raised to HIGH.
@register_task(
validator=content_tasks.RemoteChannelResourcesImportValidator,
track_progress=True,
cancellable=True,
permission_classes=[CanManageContent],
priority=Priority.HIGH,
queue=QUEUE,
long_running=True,
status_fn=content_tasks.get_status,
)
def remotecontentimport(*args, **kwargs):
return content_tasks.remotecontentimport.func(*args, **kwargs)


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

0 comments on commit 5017480

Please sign in to comment.