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

feat: Add an experimental custom attr for automatic Celery task code owner #33180

Merged
merged 1 commit into from
Sep 6, 2023
Merged
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
21 changes: 21 additions & 0 deletions lms/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import os

from celery.signals import task_prerun
from django.dispatch import receiver
from edx_django_utils.monitoring import set_custom_attribute

# Patch the xml libs before anything else.
from openedx.core.lib.safe_lxml import defuse_xml_libs

Expand All @@ -17,3 +21,20 @@
# and then instantiate the Celery singleton.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lms.envs.production')
from openedx.core.lib.celery import APP # pylint: disable=wrong-import-position,unused-import


@receiver(task_prerun)
def set_code_owner_on_celery_tasks(*, task, **kwargs):
"""
Sets the `code_owner` custom attribute on all Celery tasks, obviating the
need for the set_code_owner_attribute task decorator.

...or rather, we're not yet sure whether this works, so we're setting a
different custom attribute first.

See https://github.com/openedx/edx-platform/issues/33179 for details.
"""
try:
set_custom_attribute("auto_celery_code_owner_module", task.__module__)
except Exception as e: # pylint: disable=broad-except
set_custom_attribute("auto_celery_code_owner_error", repr(e))
Loading