Skip to content

Commit

Permalink
feat: Add an experimental custom attr for automatic Celery task code …
Browse files Browse the repository at this point in the history
…owner (#33180)
  • Loading branch information
timmc-edx authored Sep 6, 2023
1 parent c01ccaf commit a1d840f
Showing 1 changed file with 21 additions and 0 deletions.
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))

0 comments on commit a1d840f

Please sign in to comment.