Files
edx-platform/cms/djangoapps/export_course_metadata/tasks.py
Tim McCormack 83f6e560b7 fix: Add code_owner decorator to remaining Celery tasks (#31762)
This will ensure that errors raised by these tasks will alert the right
team. `send_course_enrollment_email` is the one I set out to fix, but I
discovered a few others.

I located tasks that were missing decorators by running the following
search and visually inspecting the results, although semgrep might be able
to do better:

```
ack '^@.*task|^@set_code_owner_attribute' cms lms common openedx xmodule --ignore-dir=tests --python
```

Also, add more detailed explanation of why a couple of tasks can't use the
decorator. This should only be an issue on tasks inheriting from
UserTaskMixin, which in practice is just CourseExportTask and
CourseImportTask (and the apparently unused EnrollmentReadTask and
EnrollmentWriteTask), via UserTask.
2023-02-15 18:20:50 +00:00

34 lines
1.2 KiB
Python

"""
This file exports metadata about the course
"""
import json
from celery import shared_task
from django.core.files.base import ContentFile
from edx_django_utils.monitoring import set_code_owner_attribute
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.schedules.content_highlights import get_all_course_highlights
from .storage import course_metadata_export_storage
@shared_task(bind=True)
@set_code_owner_attribute
def export_course_metadata_task(self, course_key_string): # pylint: disable=unused-argument
"""
Export course metadata
File format
'{"highlights": [["week1highlight1", "week1highlight2"], ["week1highlight1", "week1highlight2"], [], []]}'
To retrieve highlights for week1, you would need to do
course_metadata['highlights'][0]
This data is initially being used by Braze Connected Content to include
section highlights in emails, but may be used for other things in the future.
"""
course_key = CourseKey.from_string(course_key_string)
highlights = get_all_course_highlights(course_key)
highlights_content = ContentFile(json.dumps({'highlights': highlights}))
course_metadata_export_storage.save(f'course_metadata_export/{course_key}.json', highlights_content)