-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
temp: Possible repro branch for DD trace concatenation
- Add `/celery_repro` URL to run a sample task - Send Celery tasks to a broker, rather than running in-process - Hardcode a broker URL - Log all celery signals See edx/edx-arch-experiments#692
- Loading branch information
Showing
6 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from openedx.core.djangoapps.celery_repro.views import run_celery_task | ||
|
||
urlpatterns = [ | ||
path('', run_celery_task, name='celery_repro'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ddtrace.tracer | ||
from celery import shared_task | ||
from common.djangoapps.util.json_request import JsonResponse | ||
|
||
|
||
@shared_task | ||
def sample_task(): | ||
print("📋📋📋 Task is running in this process.") | ||
|
||
|
||
def run_celery_task(request): | ||
print(f"ℹ️ Current root span: {ddtrace.tracer.current_root_span()._pprint()}") | ||
sample_task.apply_async() | ||
return JsonResponse({}, status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,34 @@ | |
|
||
# WARNING: Do not refer to this unless you are cms.celery or | ||
# lms.celery. See module docstring! | ||
APP = Celery('proj') | ||
APP = Celery('proj', broker="redis://:[email protected]:6379/10") | ||
|
||
APP.conf.task_protocol = 1 | ||
# Using a string here means the worker will not have to | ||
# pickle the object when using Windows. | ||
APP.config_from_object('django.conf:settings') | ||
APP.autodiscover_tasks() | ||
|
||
|
||
import celery.signals | ||
|
||
CELERY_SIGNAL_NAMES = [ | ||
'before_task_publish', | ||
'after_task_publish', | ||
'task_prerun', | ||
'task_postrun', | ||
'task_retry', | ||
'task_success', | ||
'task_failure', | ||
'task_internal_error', | ||
'task_received', | ||
'task_revoked', | ||
'task_unknown', | ||
'task_rejected', | ||
] | ||
|
||
def log_celery_signal(*args, **kwargs): | ||
print(f"⚠️⚠️⚠️ Celery signal received: {args=} {kwargs=}") | ||
|
||
for signal_name in CELERY_SIGNAL_NAMES: | ||
getattr(celery.signals, signal_name).connect(log_celery_signal, weak=False) |