set code_owner for celery tasks

ARCHBOM-1260

Co-authored-by: Tim McCormack <tmccormack@edx.org>
This commit is contained in:
Robert Raposa
2020-11-12 23:19:42 -05:00
parent 6a55b833dc
commit 8eef18710d
30 changed files with 98 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ from django.core.files import File
from django.test import RequestFactory
from django.utils.text import get_valid_filename
from django.utils.translation import ugettext as _
from edx_django_utils.monitoring import set_code_owner_attribute, set_code_owner_attribute_from_module
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocator
from organizations.models import OrganizationCourse
@@ -83,6 +84,7 @@ def clone_instance(instance, field_values):
@task()
@set_code_owner_attribute
def rerun_course(source_course_key_string, destination_course_key_string, user_id, fields=None):
"""
Reruns a course in a new celery task.
@@ -169,6 +171,7 @@ def _parse_time(time_isoformat):
@task(routing_key=settings.UPDATE_SEARCH_INDEX_JOB_QUEUE)
@set_code_owner_attribute
def update_search_index(course_id, triggered_time_isoformat):
""" Updates course search index. """
try:
@@ -193,6 +196,7 @@ def update_search_index(course_id, triggered_time_isoformat):
@task()
@set_code_owner_attribute
def update_library_index(library_id, triggered_time_isoformat):
""" Updates course search index. """
try:
@@ -238,10 +242,13 @@ class CourseExportTask(UserTask): # pylint: disable=abstract-method
@task(base=CourseExportTask, bind=True)
# Note: The decorator @set_code_owner_attribute could not be used because
# the implementation of this task breaks with any additional decorators.
def export_olx(self, user_id, course_key_string, language):
"""
Export a course or library to an OLX .tar.gz archive and prepare it for download.
"""
set_code_owner_attribute_from_module(__name__)
courselike_key = CourseKey.from_string(course_key_string)
try:
@@ -370,10 +377,13 @@ class CourseImportTask(UserTask): # pylint: disable=abstract-method
@task(base=CourseImportTask, bind=True)
# Note: The decorator @set_code_owner_attribute could not be used because
# the implementation of this task breaks with any additional decorators.
def import_olx(self, user_id, course_key_string, archive_path, archive_name, language):
"""
Import a course or library from a provided OLX .tar.gz archive.
"""
set_code_owner_attribute_from_module(__name__)
courselike_key = CourseKey.from_string(course_key_string)
try:
user = User.objects.get(pk=user_id)