File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
background/celery/tasks/docprocessing Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 92
92
from onyx .redis .redis_utils import is_fence
93
93
from onyx .server .runtime .onyx_runtime import OnyxRuntime
94
94
from onyx .utils .logger import setup_logger
95
- from onyx .utils .logger import TaskAttemptSingleton
96
95
from onyx .utils .middleware import make_randomized_onyx_request_id
97
96
from onyx .utils .telemetry import optional_telemetry
98
97
from onyx .utils .telemetry import RecordType
99
98
from shared_configs .configs import INDEXING_MODEL_SERVER_HOST
100
99
from shared_configs .configs import INDEXING_MODEL_SERVER_PORT
101
100
from shared_configs .configs import MULTI_TENANT
102
101
from shared_configs .contextvars import CURRENT_TENANT_ID_CONTEXTVAR
102
+ from shared_configs .contextvars import INDEX_ATTEMPT_INFO_CONTEXTVAR
103
103
104
104
logger = setup_logger ()
105
105
@@ -1085,9 +1085,9 @@ def _docprocessing_task(
1085
1085
) -> None :
1086
1086
start_time = time .monotonic ()
1087
1087
1088
- # set the indexing attempt ID so that all log messages from this process
1089
- # will have it added as a prefix
1090
- TaskAttemptSingleton . set_cc_and_index_id ( index_attempt_id , cc_pair_id )
1088
+ # Cannot use the TaskSingleton approach here because the worker is multithreaded
1089
+ INDEX_ATTEMPT_INFO_CONTEXTVAR . set (( cc_pair_id , index_attempt_id ))
1090
+ task_logger
1091
1091
if tenant_id :
1092
1092
CURRENT_TENANT_ID_CONTEXTVAR .set (tenant_id )
1093
1093
Original file line number Diff line number Diff line change 13
13
from shared_configs .configs import SLACK_CHANNEL_ID
14
14
from shared_configs .configs import TENANT_ID_PREFIX
15
15
from shared_configs .contextvars import CURRENT_TENANT_ID_CONTEXTVAR
16
+ from shared_configs .contextvars import INDEX_ATTEMPT_INFO_CONTEXTVAR
16
17
from shared_configs .contextvars import ONYX_REQUEST_ID_CONTEXTVAR
17
18
18
19
@@ -102,8 +103,14 @@ def process(
102
103
msg = f"[Doc Permissions Sync: { doc_permission_sync_ctx_dict ['request_id' ]} ] { msg } "
103
104
break
104
105
105
- index_attempt_id = TaskAttemptSingleton .get_index_attempt_id ()
106
- cc_pair_id = TaskAttemptSingleton .get_connector_credential_pair_id ()
106
+ index_attempt_info = INDEX_ATTEMPT_INFO_CONTEXTVAR .get ()
107
+ if index_attempt_info :
108
+ cc_pair_id : int | None = index_attempt_info [0 ]
109
+ index_attempt_id : int | None = index_attempt_info [1 ]
110
+
111
+ else :
112
+ index_attempt_id = TaskAttemptSingleton .get_index_attempt_id ()
113
+ cc_pair_id = TaskAttemptSingleton .get_connector_credential_pair_id ()
107
114
108
115
if index_attempt_id is not None :
109
116
msg = f"[Index Attempt: { index_attempt_id } ] { msg } "
Original file line number Diff line number Diff line change 21
21
"onyx_request_id" , default = None
22
22
)
23
23
24
+ # Used to store cc pair id and index attempt id in multithreaded environments
25
+ INDEX_ATTEMPT_INFO_CONTEXTVAR : contextvars .ContextVar [tuple [int , int ] | None ] = (
26
+ contextvars .ContextVar ("index_attempt_info" , default = None )
27
+ )
28
+
24
29
"""Utils related to contextvars"""
25
30
26
31
You can’t perform that action at this time.
0 commit comments