File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
django_declarative_apis/machinery Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ # [ 0.25.2] - 2023-01-20
8
+ ### Fixed
9
+ - [ PR 120] ( https://github.com/salesforce/django-declarative-apis/pull/120 ) Fix correlation ID logging for deferred tasks
10
+
7
11
# [ 0.25.1] - 2022-12-19
8
12
### Fixed
9
13
- [ PR 117] ( https://github.com/salesforce/django-declarative-apis/pull/117 ) Fix README specification in pyproject.toml
Original file line number Diff line number Diff line change 26
26
import cid .locals
27
27
28
28
_get_correlation_id = cid .locals .get_cid
29
+ _set_correlation_id = cid .locals .set_cid
29
30
except ImportError :
30
31
_get_correlation_id = lambda : None # noqa: E731
32
+ _set_correlation_id = lambda _ : None # noqa: E731
31
33
32
34
JOB_COUNT_CACHE_KEY = "future_task_runner:job_id"
33
35
QUEUE_LENGTH_CACHE_KEY = "future_task_runner:current_queue_length"
@@ -151,6 +153,8 @@ def future_task_runner(
151
153
resource_instance = resource_class .objects .get (pk = resource_instance_id )
152
154
endpoint_task = getattr (endpoint_class , endpoint_method_name )
153
155
156
+ _set_correlation_id (correlation_id )
157
+
154
158
_log_task_stats (
155
159
endpoint_method_name ,
156
160
resource_instance_id ,
@@ -291,6 +295,8 @@ def resource_task_runner(
291
295
resource_instance = resource_class .objects .get (pk = resource_instance_id )
292
296
resource_method = getattr (resource_instance , resource_method_name )
293
297
298
+ _set_correlation_id (correlation_id )
299
+
294
300
_log_task_stats (
295
301
"{0}.{1}" .format (resource_class_name , resource_method_name ),
296
302
resource_instance_id ,
Original file line number Diff line number Diff line change @@ -820,6 +820,38 @@ def setUp(self):
820
820
"filtered_retry_count_2" : 0 ,
821
821
}
822
822
823
+ def test_future_task_runner_sets_cid (self ):
824
+ data = {"cid" : None }
825
+
826
+ def set_correlation_id (cid ):
827
+ data ["cid" ] = cid
828
+
829
+ conf = tasks .future_task_runner .app .conf
830
+ old_val = conf ["task_always_eager" ]
831
+ conf ["task_always_eager" ] = True
832
+
833
+ old_set_cid = tasks ._set_correlation_id
834
+ old_get_cid = tasks ._get_correlation_id
835
+ tasks ._set_correlation_id = set_correlation_id
836
+ tasks ._get_correlation_id = lambda : "cid-sentinel"
837
+ try :
838
+ expected_response = {"foo" : "bar" }
839
+ endpoint = _TestEndpoint (expected_response )
840
+ manager = machinery .EndpointBinder .BoundEndpointManager (
841
+ machinery ._EndpointRequestLifecycleManager (endpoint ), endpoint
842
+ )
843
+ machinery .EndpointBinder (endpoint ).create_bound_endpoint (
844
+ manager , HttpRequest ()
845
+ )
846
+
847
+ manager .get_response ()
848
+ finally :
849
+ tasks ._set_correlation_id = old_set_cid
850
+ tasks ._get_correlation_id = old_get_cid
851
+ conf ["task_always_eager" ] = old_val
852
+
853
+ self .assertEqual ("cid-sentinel" , data ["cid" ])
854
+
823
855
def test_get_response_kombu_error_retried (self ):
824
856
expected_response = {"foo" : "bar" }
825
857
endpoint = _TestEndpoint (expected_response )
You can’t perform that action at this time.
0 commit comments