fdc-shared-kernel 0.0.71__tar.gz → 0.0.73__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/PKG-INFO +1 -1
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/PKG-INFO +1 -1
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/SOURCES.txt +2 -1
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/pyproject.toml +1 -1
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/event_executor/event_executor.py +38 -7
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/logger/__init__.py +26 -11
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/aws_databus.py +2 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/utils/event_messages.py +3 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/registries/service_event_registry.py +2 -2
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/status_tracker/status_tracker.py +13 -6
- fdc_shared_kernel-0.0.73/shared_kernel/utils/thread_local_util.py +63 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/README.md +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/README_pypi.md +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/dependency_links.txt +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/requires.txt +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/top_level.txt +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/requirements.txt +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/setup.cfg +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/async_task_executor/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/async_task_executor/async_task_executor.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/auth/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/auth/jwt_helper.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/auth/token_handler.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/config/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/database/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/enums/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/enums/async_task_executor.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/enums/status_tracker.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/event_executor/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/event_executor/utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/configuration_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/custom_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/data_validation_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/http_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/infrastructure_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/operational_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/security_exceptions.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/http/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/http/httpx_http_client.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/http/request_http_client.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/interfaces/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/interfaces/databus.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/interfaces/http.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/interfaces/keyvault.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/http_databus.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/nats_databus.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/nats_publisher.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/nats_test.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/utils/aws_utility.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/metrics/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/metrics/status_tracker.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/models/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/registries/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/security/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/security/key_vault/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/security/key_vault/aws_secret_manager.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/security/key_vault/azure_keyvault.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/status_tracker/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/config/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/config/test_config.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/logger/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/logger/test_logger.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/messaging/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/messaging/test_aws_databus.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/messaging/test_event_executor.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/messaging/test_nats_interface.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/utils/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/utils/test_data_validators.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/utils/test_date_format_utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/utils/test_string_utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/__init__.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/data_validators_utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/date_format_utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/string_utils.py +0 -0
- {fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/template_renderer.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fdc_shared_kernel
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.73
|
|
4
4
|
Summary: Shared library for microservice
|
|
5
5
|
Author-email: Shikhil S <shikhil.s@dbizsolution.com>, Ahammed Akdham N <ahammedakdham.n@dbizsolution.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fdc_shared_kernel
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.73
|
|
4
4
|
Summary: Shared library for microservice
|
|
5
5
|
Author-email: Shikhil S <shikhil.s@dbizsolution.com>, Ahammed Akdham N <ahammedakdham.n@dbizsolution.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/SOURCES.txt
RENAMED
|
@@ -73,4 +73,5 @@ shared_kernel/utils/__init__.py
|
|
|
73
73
|
shared_kernel/utils/data_validators_utils.py
|
|
74
74
|
shared_kernel/utils/date_format_utils.py
|
|
75
75
|
shared_kernel/utils/string_utils.py
|
|
76
|
-
shared_kernel/utils/template_renderer.py
|
|
76
|
+
shared_kernel/utils/template_renderer.py
|
|
77
|
+
shared_kernel/utils/thread_local_util.py
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/event_executor/event_executor.py
RENAMED
|
@@ -11,10 +11,14 @@ from shared_kernel.logger import Logger
|
|
|
11
11
|
from shared_kernel.messaging.utils.event_messages import AWSEventMessage, EventMessage
|
|
12
12
|
from shared_kernel.status_tracker import StatusTracker
|
|
13
13
|
from shared_kernel.enums import TaskStatus
|
|
14
|
+
from shared_kernel.utils.thread_local_util import ThreadLocalStorage
|
|
15
|
+
|
|
14
16
|
|
|
15
17
|
app_config = Config()
|
|
16
18
|
logger = Logger(app_config.get("APP_NAME"))
|
|
17
19
|
|
|
20
|
+
thread_local_storage = ThreadLocalStorage()
|
|
21
|
+
|
|
18
22
|
class EventExecutor:
|
|
19
23
|
|
|
20
24
|
_instance = None
|
|
@@ -81,10 +85,14 @@ class EventExecutor:
|
|
|
81
85
|
logger.info(
|
|
82
86
|
f"Processing event {event_msg.event_name}. trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.trace_id}."
|
|
83
87
|
)
|
|
84
|
-
task: dict = self.status_tracker.get_task(
|
|
85
|
-
task=event_msg.event_name, task_id=event_msg.event_meta.job_id
|
|
86
|
-
)
|
|
87
88
|
|
|
89
|
+
task_details = self.status_tracker.get_task(task_details = event_msg)
|
|
90
|
+
if task_details is not None and task_details["is_duplicate"]:
|
|
91
|
+
logger.info(
|
|
92
|
+
f"Duplicate task {event_msg.event_name} is already in progress. trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.trace_id}."
|
|
93
|
+
)
|
|
94
|
+
return
|
|
95
|
+
task = task_details.get("task_details") if task_details is not None else None
|
|
88
96
|
if task is None:
|
|
89
97
|
logger.info(
|
|
90
98
|
f"Creating new task for event {event_msg.event_name}. trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.trace_id}."
|
|
@@ -95,6 +103,8 @@ class EventExecutor:
|
|
|
95
103
|
task=event_msg.event_name,
|
|
96
104
|
status=TaskStatus.PROCESSING.value,
|
|
97
105
|
task_id=event_msg.event_meta.job_id,
|
|
106
|
+
org_id=event_msg.event_meta.org_id,
|
|
107
|
+
entity_id=event_msg.event_meta.entity_id,
|
|
98
108
|
)
|
|
99
109
|
|
|
100
110
|
# setting tracking payload without the time taken and end time
|
|
@@ -143,6 +153,8 @@ class EventExecutor:
|
|
|
143
153
|
logger.error(
|
|
144
154
|
f"Error processing event {event_msg.event_name} trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.trace_id} : {str(e)}"
|
|
145
155
|
)
|
|
156
|
+
logger.info("Error processing event",type="distributed_trace",is_success="False",failure_reason=str(e))
|
|
157
|
+
|
|
146
158
|
# adding the failure reason to the event meta
|
|
147
159
|
event_msg.event_meta.failure_reason = str(e)
|
|
148
160
|
|
|
@@ -203,16 +215,28 @@ class EventExecutor:
|
|
|
203
215
|
logger.info(f"Initiating callback for message: {message}")
|
|
204
216
|
event_msg = AWSEventMessage(message)
|
|
205
217
|
event_name = event_msg.event_name
|
|
218
|
+
|
|
219
|
+
# Set thread-local context
|
|
220
|
+
thread_local_storage.set_all({
|
|
221
|
+
"trace_id": event_msg.event_meta.trace_id,
|
|
222
|
+
"span_id": event_msg.event_meta.span_id,
|
|
223
|
+
"org_id": event_msg.event_meta.org_id if hasattr(event_msg.event_meta, 'org_id') else None,
|
|
224
|
+
"event_name": event_msg.event_name,
|
|
225
|
+
"event_payload": json.dumps(event_msg.event_payload)
|
|
226
|
+
})
|
|
227
|
+
logger.info("Event recieved",type="distributed_trace")
|
|
228
|
+
# Process the message
|
|
206
229
|
success = self._process_message(event_msg, callback)
|
|
207
|
-
finally:
|
|
208
230
|
|
|
209
|
-
|
|
231
|
+
finally:
|
|
232
|
+
# Update the event stats whether it succeeded or failed
|
|
210
233
|
if event_name:
|
|
211
234
|
self._update_event_stats(event_name, success)
|
|
212
235
|
|
|
213
236
|
if success:
|
|
214
237
|
logger.info(
|
|
215
|
-
f"Event {event_msg.event_name} completed successfully.
|
|
238
|
+
f"Event {event_msg.event_name} completed successfully. "
|
|
239
|
+
f"trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.span_id}."
|
|
216
240
|
)
|
|
217
241
|
self.status_tracker.update_task(
|
|
218
242
|
span_id=event_msg.event_meta.span_id,
|
|
@@ -221,10 +245,17 @@ class EventExecutor:
|
|
|
221
245
|
status=TaskStatus.COMPLETED.value,
|
|
222
246
|
task_id=event_msg.event_meta.job_id,
|
|
223
247
|
)
|
|
248
|
+
logger.info("Event processed successfully",type="distributed_trace",is_success="True",time_in_seconds= event_msg.event_meta.time_taken)
|
|
224
249
|
else:
|
|
225
250
|
logger.warning(
|
|
226
|
-
f"Event {event_msg.event_name} failed during processing.
|
|
251
|
+
f"Event {event_msg.event_name} failed during processing. "
|
|
252
|
+
f"trace-id: {event_msg.event_meta.trace_id}. span-id: {event_msg.event_meta.span_id}."
|
|
227
253
|
)
|
|
254
|
+
|
|
255
|
+
# Clean up thread-local storage
|
|
256
|
+
thread_local_storage.clear()
|
|
257
|
+
|
|
258
|
+
# Delete the message from the queue
|
|
228
259
|
self.databus.delete_message(event_msg)
|
|
229
260
|
|
|
230
261
|
def _task_done_callback(self, future: Future, event_name: str, event_semaphore: Semaphore) -> None:
|
|
@@ -2,6 +2,7 @@ import logging
|
|
|
2
2
|
import os
|
|
3
3
|
import json
|
|
4
4
|
from shared_kernel.config import Config
|
|
5
|
+
from shared_kernel.utils.thread_local_util import ThreadLocalStorage
|
|
5
6
|
class JSONFormatter(logging.Formatter):
|
|
6
7
|
"""
|
|
7
8
|
Custom JSON formatter to structure log records as JSON.
|
|
@@ -16,10 +17,24 @@ class JSONFormatter(logging.Formatter):
|
|
|
16
17
|
"level": record.levelname,
|
|
17
18
|
"message": record.getMessage(),
|
|
18
19
|
}
|
|
19
|
-
if
|
|
20
|
-
|
|
20
|
+
# Get meta_data if present
|
|
21
|
+
meta_data = getattr(record, 'meta_data', {})
|
|
22
|
+
|
|
23
|
+
# Check if 'type' is in meta_data and is 'distributed_trace'
|
|
24
|
+
if meta_data.get("type") == "distributed_trace":
|
|
25
|
+
thread_context = ThreadLocalStorage.get_all()
|
|
26
|
+
# Add each data from thread local storage
|
|
27
|
+
log_record["trace_id"] = thread_context.get("trace_id")
|
|
28
|
+
log_record["span_id"] = thread_context.get("span_id")
|
|
29
|
+
log_record["org_id"] = thread_context.get("org_id")
|
|
30
|
+
log_record["event_name"] = thread_context.get("event_name")
|
|
31
|
+
log_record["event_payload"] = thread_context.get("event_payload")
|
|
32
|
+
log_record.update(meta_data)
|
|
33
|
+
if hasattr(record, 'meta_data'):
|
|
34
|
+
log_record.update(record.meta_data)
|
|
21
35
|
if record.exc_info:
|
|
22
|
-
log_record["
|
|
36
|
+
log_record["stack_trace"] = self.formatException(record.exc_info)
|
|
37
|
+
log_record["exception"] = str(record.exc_info[1])
|
|
23
38
|
return json.dumps(log_record)
|
|
24
39
|
class Logger:
|
|
25
40
|
"""
|
|
@@ -100,17 +115,17 @@ class Logger:
|
|
|
100
115
|
self.logger.addHandler(json_file_handler)
|
|
101
116
|
|
|
102
117
|
def info(self, message, *args, **kwargs):
|
|
103
|
-
|
|
104
|
-
self.logger.info(message, *args, extra=
|
|
118
|
+
meta_data = {"meta_data": kwargs}
|
|
119
|
+
self.logger.info(message, *args, extra=meta_data, stacklevel=2)
|
|
105
120
|
|
|
106
121
|
def error(self, message, *args, **kwargs):
|
|
107
|
-
|
|
108
|
-
self.logger.error(message, exc_info=True, *args, extra=
|
|
122
|
+
meta_data = {"meta_data": kwargs}
|
|
123
|
+
self.logger.error(message, exc_info=True, *args, extra=meta_data, stacklevel=2)
|
|
109
124
|
|
|
110
125
|
def debug(self, message, *args, **kwargs):
|
|
111
|
-
|
|
112
|
-
self.logger.debug(message, *args, extra=
|
|
126
|
+
meta_data = {"meta_data": kwargs}
|
|
127
|
+
self.logger.debug(message, *args, extra=meta_data, stacklevel=2)
|
|
113
128
|
|
|
114
129
|
def warning(self, message, *args, **kwargs):
|
|
115
|
-
|
|
116
|
-
self.logger.warning(message, *args, extra=
|
|
130
|
+
meta_data = {"meta_data": kwargs}
|
|
131
|
+
self.logger.warning(message, *args, extra=meta_data, stacklevel=2)
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/aws_databus.py
RENAMED
|
@@ -70,6 +70,8 @@ class AWSDataBus(DataBus):
|
|
|
70
70
|
task=validated_event_dict["event_name"],
|
|
71
71
|
status=TaskStatus.QUEUED.value,
|
|
72
72
|
task_id=validated_event_dict["event_meta"]["job_id"],
|
|
73
|
+
org_id=validated_event_dict["event_meta"]["org_id"],
|
|
74
|
+
entity_id=validated_event_dict["event_meta"].get("entity_id", None),
|
|
73
75
|
)
|
|
74
76
|
|
|
75
77
|
self.status_tracker.set_event_meta_and_message_receipt_handle(
|
|
@@ -19,6 +19,9 @@ class EventMeta:
|
|
|
19
19
|
self.trace_id: str = meta_data.get("trace_id")
|
|
20
20
|
self.job_id: str = meta_data.get("job_id")
|
|
21
21
|
self.trigger = meta_data.get("trigger")
|
|
22
|
+
self.org_id = meta_data.get("org_id")
|
|
23
|
+
# entity_id is an optional field as some events may not be associated with an entity
|
|
24
|
+
self.entity_id = meta_data.get("entity_id", None)
|
|
22
25
|
# generate a new span_id for each event if not present already
|
|
23
26
|
self.span_id: str = meta_data.get("span_id", str(uuid.uuid4()))
|
|
24
27
|
|
|
@@ -20,9 +20,9 @@ class ServiceEventRegistry:
|
|
|
20
20
|
+ "/event/subscribe-sync-event/MARK_TASK_AS_FAILURE/"
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
PROCESS_TASK = (
|
|
24
24
|
config.get("MASTER_SERVICE_BASE_ENDPOINT")
|
|
25
|
-
+ "/event/subscribe-sync-event/
|
|
25
|
+
+ "/event/subscribe-sync-event/PROCESS_TASK/"
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
GET_IN_PROGRESS_TASK = (
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/status_tracker/status_tracker.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from shared_kernel.exceptions.custom_exceptions import StatusTrackerException
|
|
2
2
|
from shared_kernel.interfaces.databus import DataBus
|
|
3
3
|
from shared_kernel.messaging import DataBusFactory
|
|
4
|
+
from shared_kernel.messaging.utils.event_messages import EventMessage
|
|
4
5
|
from shared_kernel.registries.service_event_registry import ServiceEventRegistry
|
|
5
6
|
|
|
6
7
|
service_event_registry = ServiceEventRegistry()
|
|
@@ -32,7 +33,7 @@ class StatusTracker:
|
|
|
32
33
|
)
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
def create_task(self, span_id, trace_id, task, status, task_id):
|
|
36
|
+
def create_task(self, span_id, trace_id, task, status, task_id, org_id, entity_id=None):
|
|
36
37
|
"""Publishes a synchronous event to create a task"""
|
|
37
38
|
try:
|
|
38
39
|
payload = {
|
|
@@ -41,7 +42,10 @@ class StatusTracker:
|
|
|
41
42
|
"task": task,
|
|
42
43
|
"status": status,
|
|
43
44
|
"task_id": task_id,
|
|
45
|
+
"org_id": org_id,
|
|
44
46
|
}
|
|
47
|
+
if entity_id:
|
|
48
|
+
payload["entity_id"] = entity_id
|
|
45
49
|
response = self.databus.request_event(
|
|
46
50
|
getattr(service_event_registry, "CREATE_TASK"), payload
|
|
47
51
|
)
|
|
@@ -89,15 +93,19 @@ class StatusTracker:
|
|
|
89
93
|
raise StatusTrackerException(e)
|
|
90
94
|
|
|
91
95
|
|
|
92
|
-
def get_task(self,
|
|
96
|
+
def get_task(self, task_details: EventMessage):
|
|
93
97
|
"""Publishes a synchronous event to retrieve a task"""
|
|
94
98
|
try:
|
|
95
99
|
payload = {
|
|
96
|
-
"task":
|
|
97
|
-
"task_id":
|
|
100
|
+
"task": task_details.event_name,
|
|
101
|
+
"task_id": task_details.event_meta.job_id,
|
|
102
|
+
"entity_id": task_details.event_meta.entity_id if task_details.event_meta.entity_id else None,
|
|
103
|
+
"trace_id": task_details.event_meta.trace_id,
|
|
104
|
+
"span_id": task_details.event_meta.span_id,
|
|
105
|
+
"org_id": task_details.event_meta.org_id,
|
|
98
106
|
}
|
|
99
107
|
response: dict = self.databus.request_event(
|
|
100
|
-
getattr(service_event_registry, "
|
|
108
|
+
getattr(service_event_registry, "PROCESS_TASK"), payload
|
|
101
109
|
)
|
|
102
110
|
return response.get("data")
|
|
103
111
|
|
|
@@ -155,4 +163,3 @@ class StatusTracker:
|
|
|
155
163
|
|
|
156
164
|
except Exception as e:
|
|
157
165
|
raise StatusTrackerException(e)
|
|
158
|
-
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ThreadLocalStorage:
|
|
5
|
+
"""
|
|
6
|
+
Utility class for managing thread-local storage with class-level methods and variables.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Class-level thread-local storage
|
|
10
|
+
_storage = threading.local()
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def set(cls, key: str, value: any) -> None:
|
|
14
|
+
"""
|
|
15
|
+
Sets a value in the thread-local storage.
|
|
16
|
+
|
|
17
|
+
:param key: The key for the value.
|
|
18
|
+
:param value: The value to be stored.
|
|
19
|
+
"""
|
|
20
|
+
if not hasattr(cls._storage, "data"):
|
|
21
|
+
cls._storage.data = {}
|
|
22
|
+
cls._storage.data[key] = value
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def set_all(cls, values: dict) -> None:
|
|
26
|
+
"""
|
|
27
|
+
Sets multiple key-value pairs in the thread-local storage.
|
|
28
|
+
|
|
29
|
+
:param values: A dictionary of key-value pairs to store.
|
|
30
|
+
"""
|
|
31
|
+
if not hasattr(cls._storage, "data"):
|
|
32
|
+
cls._storage.data = {}
|
|
33
|
+
cls._storage.data.update(values)
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def get(cls, key: str, default=None) -> any:
|
|
37
|
+
"""
|
|
38
|
+
Retrieves a value from the thread-local storage.
|
|
39
|
+
|
|
40
|
+
:param key: The key for the value.
|
|
41
|
+
:param default: The default value to return if the key is not found.
|
|
42
|
+
:return: The value associated with the key, or the default value.
|
|
43
|
+
"""
|
|
44
|
+
if hasattr(cls._storage, "data") and key in cls._storage.data:
|
|
45
|
+
return cls._storage.data[key]
|
|
46
|
+
return default
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def get_all(cls) -> dict:
|
|
50
|
+
"""
|
|
51
|
+
Retrieves all key-value pairs from the thread-local storage.
|
|
52
|
+
|
|
53
|
+
:return: A dictionary of all thread-local data.
|
|
54
|
+
"""
|
|
55
|
+
return getattr(cls._storage, "data", {}).copy() if hasattr(cls._storage, "data") else {}
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def clear(cls) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Clears all values from the thread-local storage.
|
|
61
|
+
"""
|
|
62
|
+
if hasattr(cls._storage, "data"):
|
|
63
|
+
cls._storage.data.clear()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/requires.txt
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/fdc_shared_kernel.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/async_task_executor/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/enums/async_task_executor.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/event_executor/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/custom_exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/exceptions/http_exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/http/httpx_http_client.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/http/request_http_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/http_databus.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/nats_databus.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/nats_publisher.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/messaging/utils/aws_utility.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/metrics/status_tracker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/security/key_vault/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/status_tracker/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/config/__init__.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/config/test_config.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/logger/__init__.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/logger/test_logger.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/messaging/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/tests/utils/test_string_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/data_validators_utils.py
RENAMED
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/date_format_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{fdc_shared_kernel-0.0.71 → fdc_shared_kernel-0.0.73}/shared_kernel/utils/template_renderer.py
RENAMED
|
File without changes
|