Skip to content

Commit 135a747

Browse files
author
Drew Shafer
committed
update correlation_id if cid module installed
Fixes #119
1 parent 500ba3f commit 135a747

File tree

1 file changed

+8
-0
lines changed
  • django_declarative_apis/machinery

1 file changed

+8
-0
lines changed

django_declarative_apis/machinery/tasks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import cid.locals
2727

2828
_get_correlation_id = cid.locals.get_cid
29+
_set_correlation_id = cid.locals.set_cid
2930
except ImportError:
3031
_get_correlation_id = lambda: None # noqa: E731
32+
_set_correlation_id = lambda _: None # noqa: E731
3133

3234
JOB_COUNT_CACHE_KEY = "future_task_runner:job_id"
3335
QUEUE_LENGTH_CACHE_KEY = "future_task_runner:current_queue_length"
@@ -151,6 +153,9 @@ def future_task_runner(
151153
resource_instance = resource_class.objects.get(pk=resource_instance_id)
152154
endpoint_task = getattr(endpoint_class, endpoint_method_name)
153155

156+
if correlation_id:
157+
_set_correlation_id(correlation_id)
158+
154159
_log_task_stats(
155160
endpoint_method_name,
156161
resource_instance_id,
@@ -291,6 +296,9 @@ def resource_task_runner(
291296
resource_instance = resource_class.objects.get(pk=resource_instance_id)
292297
resource_method = getattr(resource_instance, resource_method_name)
293298

299+
if correlation_id:
300+
_set_correlation_id(correlation_id)
301+
294302
_log_task_stats(
295303
"{0}.{1}".format(resource_class_name, resource_method_name),
296304
resource_instance_id,

0 commit comments

Comments
 (0)