atk-common 3.4.0__py3-none-any.whl → 3.6.0__py3-none-any.whl
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.
- atk_common/classes/bo_logger.py +9 -4
- atk_common/classes/env_handler.py +1 -1
- atk_common/classes/error_handler.py +3 -3
- atk_common/classes/http_response_handler.py +3 -3
- atk_common/classes/rabbitmq_consumer.py +3 -3
- atk_common/enums/log_level_enum.py +0 -1
- atk_common/interfaces/error_handler_interface.py +1 -1
- atk_common/interfaces/logger_interface.py +0 -1
- atk_common/utils/consumer_retry_handler.py +5 -5
- atk_common/utils/mq_utils.py +2 -2
- {atk_common-3.4.0.dist-info → atk_common-3.6.0.dist-info}/METADATA +1 -1
- {atk_common-3.4.0.dist-info → atk_common-3.6.0.dist-info}/RECORD +15 -15
- {atk_common-3.4.0.dist-info → atk_common-3.6.0.dist-info}/WHEEL +0 -0
- {atk_common-3.4.0.dist-info → atk_common-3.6.0.dist-info}/licenses/license.txt +0 -0
- {atk_common-3.4.0.dist-info → atk_common-3.6.0.dist-info}/top_level.txt +0 -0
atk_common/classes/bo_logger.py
CHANGED
@@ -11,9 +11,17 @@ class BoLogger(ILogger):
|
|
11
11
|
self.log_level = LogLevel.INFO
|
12
12
|
else:
|
13
13
|
self.log_level = log_level
|
14
|
-
self.component = component
|
14
|
+
self.component = self._parse_component_name(component)
|
15
15
|
self.version = version
|
16
16
|
|
17
|
+
# Example: ghcr.io/perspictech/bo-status-mq-consumer
|
18
|
+
def _parse_component_name(self, component: str) -> str:
|
19
|
+
if component.startswith("ghcr"):
|
20
|
+
parts = component.split('/')
|
21
|
+
if len(parts) == 3:
|
22
|
+
return parts[2]
|
23
|
+
return component
|
24
|
+
|
17
25
|
def _get_trace_context(self):
|
18
26
|
span = get_current_span()
|
19
27
|
ctx = span.get_span_context()
|
@@ -53,9 +61,6 @@ class BoLogger(ILogger):
|
|
53
61
|
def error(self, message: str):
|
54
62
|
self._log(LogLevel.ERROR, message)
|
55
63
|
|
56
|
-
def critical(self, message: str):
|
57
|
-
self._log(LogLevel.CRITICAL, message)
|
58
|
-
|
59
64
|
def set_level(self, log_level: LogLevel):
|
60
65
|
self.log_level = log_level
|
61
66
|
|
@@ -28,7 +28,7 @@ class EnvHandler(IEnvHandler):
|
|
28
28
|
if val is None and abort_on_error:
|
29
29
|
err_msg = f"Environment variable '{key}' is not set."
|
30
30
|
if self.logger:
|
31
|
-
self.logger.
|
31
|
+
self.logger.error(err_msg)
|
32
32
|
raise ValueError(err_msg)
|
33
33
|
if self.is_value_null_or_empty(val):
|
34
34
|
return None
|
@@ -32,9 +32,9 @@ class ErrorHandler(IErrorHandler):
|
|
32
32
|
err_str += ', imageName: <none>'
|
33
33
|
err_str += ', imageVersion: <none>'
|
34
34
|
err_str += ', containerName: <none>'
|
35
|
-
self.logger.
|
35
|
+
self.logger.error(err_str)
|
36
36
|
|
37
|
-
def get_error_entity(self, error, method, error_type, status_code
|
37
|
+
def get_error_entity(self, error, method, error_type, status_code):
|
38
38
|
data = {}
|
39
39
|
data['statusCode'] = status_code
|
40
40
|
data['exceptionType'] = str(type(error))
|
@@ -42,7 +42,7 @@ class ErrorHandler(IErrorHandler):
|
|
42
42
|
data['message'] = self.get_message(error)
|
43
43
|
data['method'] = method
|
44
44
|
data['timestamp'] = get_utc_date_time_str()
|
45
|
-
data['containerInfo'] =
|
45
|
+
data['containerInfo'] = self.docker_handler.get_current_container_info()
|
46
46
|
self.create_error_log(data)
|
47
47
|
return Response(
|
48
48
|
response=json.dumps(data),
|
@@ -27,7 +27,7 @@ class HttpResponseHandler(IHttpResponseHandler):
|
|
27
27
|
# If response['status'] == 1 (HTTP): resend received error entity
|
28
28
|
# If response['status'] == 2 (INTERNAL): create new error entity and return as response
|
29
29
|
# If http status other value: create new error entity and return as response
|
30
|
-
def http_response(self, method, response
|
30
|
+
def http_response(self, method, response):
|
31
31
|
if is_http_status_ok(response['statusCode']):
|
32
32
|
return Response(
|
33
33
|
response=self._convert_response_data(response['responseMsg']),
|
@@ -38,5 +38,5 @@ class HttpResponseHandler(IHttpResponseHandler):
|
|
38
38
|
elif is_http_status_internal(response['statusCode']):
|
39
39
|
if is_response_http(response):
|
40
40
|
return self.error_handler.resend_error_entity(response['responseMsg'])
|
41
|
-
return self.error_handler.get_error_entity(response['responseMsg'], method, ApiErrorType.INTERNAL, response['statusCode']
|
42
|
-
return self.error_handler.get_error_entity(response['responseMsg'], method, ApiErrorType.CONNECTION, response['statusCode']
|
41
|
+
return self.error_handler.get_error_entity(response['responseMsg'], method, ApiErrorType.INTERNAL, response['statusCode'])
|
42
|
+
return self.error_handler.get_error_entity(response['responseMsg'], method, ApiErrorType.CONNECTION, response['statusCode'])
|
@@ -41,10 +41,10 @@ class RabbitMQConsumer:
|
|
41
41
|
self.logger.debug("Socket timeout, checking heartbeat...")
|
42
42
|
conn.heartbeat_check()
|
43
43
|
except CONNECTION_ERRORS as e:
|
44
|
-
self.logger.
|
44
|
+
self.logger.error(f"Connection lost: {e}. Reconnecting...")
|
45
45
|
return # break loop and re-establish connection
|
46
46
|
except Exception as e:
|
47
|
-
self.logger.
|
47
|
+
self.logger.error(f"Top-level exception in consume loop: {e}. Restarting after delay...")
|
48
48
|
return
|
49
49
|
|
50
50
|
def _establish_connection(self):
|
@@ -68,5 +68,5 @@ class RabbitMQConsumer:
|
|
68
68
|
try:
|
69
69
|
self._consume()
|
70
70
|
except Exception as e:
|
71
|
-
self.logger.
|
71
|
+
self.logger.error(f"Top-level exception in run loop: {e}. Restarting after delay...")
|
72
72
|
time.sleep(5)
|
@@ -4,7 +4,7 @@ from typing import Protocol
|
|
4
4
|
class IErrorHandler(Protocol):
|
5
5
|
def get_message(self, error) -> None: ...
|
6
6
|
def create_error_log(self, data) -> None: ...
|
7
|
-
def get_error_entity(self, error, method, error_type, status_code
|
7
|
+
def get_error_entity(self, error, method, error_type, status_code) -> None: ...
|
8
8
|
def resend_error_entity(self, error_entity) -> None: ...
|
9
9
|
def handle_error(self, resp, status) -> None: ...
|
10
10
|
def get_response_error(self, resp) -> None: ...
|
@@ -37,19 +37,19 @@ def create_retry_handler(process_func, connection, exchange, routing_key, should
|
|
37
37
|
)
|
38
38
|
message.ack()
|
39
39
|
else:
|
40
|
-
logger.
|
40
|
+
logger.error("Sending to DLQ...")
|
41
41
|
message.reject(requeue=False)
|
42
42
|
else:
|
43
43
|
if should_retry(process_response):
|
44
|
-
logger.
|
44
|
+
logger.error("Sending to DLQ...")
|
45
45
|
message.reject(requeue=False)
|
46
|
-
# bo_logger.
|
46
|
+
# bo_logger.error("Requing...")
|
47
47
|
# message.requeue()
|
48
48
|
else:
|
49
|
-
logger.
|
49
|
+
logger.error("Discarding message...")
|
50
50
|
message.ack()
|
51
51
|
except Exception as e:
|
52
|
-
logger.
|
52
|
+
logger.error(f"Error during processing: {e}, sending to DLQ...")
|
53
53
|
message.reject(requeue=False)
|
54
54
|
|
55
55
|
return handler
|
atk_common/utils/mq_utils.py
CHANGED
@@ -23,8 +23,8 @@ def decode_message(body, message, logger: ILogger):
|
|
23
23
|
elif message.content_type.startswith('text/'):
|
24
24
|
return create_response(ResponseStatusType.OK, HTTPStatus.OK, body.decode('utf-8'))
|
25
25
|
else:
|
26
|
-
logger.
|
26
|
+
logger.error(f"Unknown message content type {message.content_type}. Cannot decode message.")
|
27
27
|
return create_response(ResponseStatusType.INTERNAL, HTTPStatus.INTERNAL_SERVER_ERROR, get_message(error))
|
28
28
|
except Exception as error:
|
29
|
-
logger.
|
29
|
+
logger.error('Error decoding message: ' + get_message(error))
|
30
30
|
return create_response(ResponseStatusType.INTERNAL, HTTPStatus.INTERNAL_SERVER_ERROR, get_message(error))
|
@@ -17,12 +17,12 @@ atk_common/mq_utils.py,sha256=6z4l7LsZWCzldsCZPsWnCtN4lIQ3gyoSuywQoQOh5Ak,1137
|
|
17
17
|
atk_common/rabbitmq_consumer.py,sha256=4MhuwZs47Jt1fX4sUxr1MKRe7o2QRbPe9_utXEsa8QE,1907
|
18
18
|
atk_common/response_utils.py,sha256=AxlmwkFoDU5XcFOzBQiuZxAQgswihpKXHSo1T0JJw3Q,556
|
19
19
|
atk_common/classes/__init__.py,sha256=O_VHYxAilmoz3i9L6jkwS-JZ4UaTezdhFiA5liNl1lY,532
|
20
|
-
atk_common/classes/bo_logger.py,sha256=
|
20
|
+
atk_common/classes/bo_logger.py,sha256=pEdk4bl0Vr60yWVihT7Fm395lMmO8JBBNeEhtDyIO5c,2250
|
21
21
|
atk_common/classes/docker_handler.py,sha256=73WiebIT_RwGgwyvIed_Q5p8Tsb1b22JChBDyUmf1IU,2949
|
22
|
-
atk_common/classes/env_handler.py,sha256=
|
23
|
-
atk_common/classes/error_handler.py,sha256=
|
24
|
-
atk_common/classes/http_response_handler.py,sha256=
|
25
|
-
atk_common/classes/rabbitmq_consumer.py,sha256=
|
22
|
+
atk_common/classes/env_handler.py,sha256=h3snKwHwDvfc2dt1vgHasqv8n_vnsI9J2MAr-XM5oow,1283
|
23
|
+
atk_common/classes/error_handler.py,sha256=TiviyBOTVcUBPjXd_DAgeUEQSvEdDCjFrAmEzTLuDVE,3272
|
24
|
+
atk_common/classes/http_response_handler.py,sha256=l8CfntLPRHbB1nfUPPGnmTvQMAM29CVK4THG4FK1_4k,2128
|
25
|
+
atk_common/classes/rabbitmq_consumer.py,sha256=jct1UnfP-PU3IeWW2S_9dQ7FxmY0_M8YwZadFMv52j8,2936
|
26
26
|
atk_common/enums/__init__.py,sha256=hOSoKWIBUpRFaMN2tNJiel6iGI1MHj229OYnU1J8Jg0,2636
|
27
27
|
atk_common/enums/api_error_type_enum.py,sha256=9oW6ZaZ3lhMwR8r2sVNWGliS9C_jV-otiOYdezAuTp0,91
|
28
28
|
atk_common/enums/camera_cabinet_type_enum.py,sha256=U2NVrsTCBgaMRwYJamnjshAW8Y7xlOVjvUzakdgVH9A,90
|
@@ -46,7 +46,7 @@ atk_common/enums/image_part_type.py,sha256=tg6W9kYMRShOlsxhAJRNRdWH50gC-eF0sqvqs
|
|
46
46
|
atk_common/enums/image_part_type_enum.py,sha256=NREEtLNMVVFo-RiOWR_krUSZWRscWMCo2PHHTnZnmLg,113
|
47
47
|
atk_common/enums/image_shelf_type.py,sha256=m2-nWi83tWi-KYpTMphyt-yhK5iGNvHrJBNYjodx1P4,84
|
48
48
|
atk_common/enums/image_shelf_type_enum.py,sha256=m2-nWi83tWi-KYpTMphyt-yhK5iGNvHrJBNYjodx1P4,84
|
49
|
-
atk_common/enums/log_level_enum.py,sha256=
|
49
|
+
atk_common/enums/log_level_enum.py,sha256=FxLCM0WQefqmAIA-I8TZNFalDgcMv7c85HDeUZcUIHA,110
|
50
50
|
atk_common/enums/metering_direction_enum.py,sha256=ramBPt0fK_NsToCqiYmtzDVNsLVGbeF39TmSpn_ghTY,107
|
51
51
|
atk_common/enums/multimotor_status_type_enum.py,sha256=TaoqSb6OjU17VAmFun28o8XhU3fkAKg_TQ9Kq8Y0Ff4,88
|
52
52
|
atk_common/enums/piezo_vehicle_type_enum.py,sha256=tlFk9dP7KkJVBna8SIJf6MH9zJD_szSUcDxFATJ6LZE,89
|
@@ -66,11 +66,11 @@ atk_common/enums/violation_type_enum.py,sha256=01qTHOj-O8bOc-nwIHVnxLosm4cusD_Yu
|
|
66
66
|
atk_common/interfaces/__init__.py,sha256=HynEg28Uy3msO7qd__VxajTasSe9-Evpj9yi3Uw2NTo,508
|
67
67
|
atk_common/interfaces/docker_handler_interface.py,sha256=aCJ6cELRlrbZC-sB-RQEpKhChCMEiYNclcfr62YjSCo,411
|
68
68
|
atk_common/interfaces/env_handler_interface.py,sha256=yrmtTplH5tnuOAs7CW5RtzLMTE5q9sdzTYjiS2naNQQ,300
|
69
|
-
atk_common/interfaces/error_handler_interface.py,sha256=
|
69
|
+
atk_common/interfaces/error_handler_interface.py,sha256=ErhQ69T3fCYUl6sS5GwiMgW-znapmGcmgWLR2QLNu8c,506
|
70
70
|
atk_common/interfaces/http_response_handler_interface.py,sha256=QjDmhVj4AnUyoRtSHk_sfFPI-cto6TV7Mx2_87tiOrs,185
|
71
|
-
atk_common/interfaces/logger_interface.py,sha256=
|
71
|
+
atk_common/interfaces/logger_interface.py,sha256=36impIkvGZbL5CUMKyaLkYi3jVyin_KRRUqvtyMh05E,381
|
72
72
|
atk_common/utils/__init__.py,sha256=IaP851DJXND3OPkjy-OJxpaNG1zkGlg5bHsUg7mqr-I,1768
|
73
|
-
atk_common/utils/consumer_retry_handler.py,sha256
|
73
|
+
atk_common/utils/consumer_retry_handler.py,sha256=-qnqxA07XLn0KKOGJCuyixqwmWYzM3g8Ii-ei2At3bY,2559
|
74
74
|
atk_common/utils/datetime_utils.py,sha256=h3tv6iPD4peBXLCAcws41nuxIM4KpR1vk71LYXTDHKo,3662
|
75
75
|
atk_common/utils/db_utils.py,sha256=odUtXcS7Mumw5eGyVyVimL_U_lP7TqMX9v8nWO5nMvg,902
|
76
76
|
atk_common/utils/default_should_retry.py,sha256=qghFbU71ygC8ARc0jkbDlxwZtwEPUqO8vGhIhGJX-Ao,838
|
@@ -79,8 +79,8 @@ atk_common/utils/file_utils.py,sha256=UDwcRquO9IrqRrlUM0t-_g4R1-FKt8ZqQinSEqXOAk
|
|
79
79
|
atk_common/utils/hash_utils.py,sha256=S_9o89CdI4lUQbVaqc85TDcqyDNuo30_E3VBaOrZKko,1047
|
80
80
|
atk_common/utils/http_utils.py,sha256=eSRuQeDgN0ISQdByZqE6cIGXoorcAXz7PEtVntHUKAo,670
|
81
81
|
atk_common/utils/internal_response_utils.py,sha256=2X9eLFEy1pO3Aesj1IRXg2yprwNcBDM5_dXaA5vfmMI,694
|
82
|
-
atk_common/utils/mq_utils.py,sha256=
|
83
|
-
atk_common-3.
|
82
|
+
atk_common/utils/mq_utils.py,sha256=DmVcXIZHG45p7cQVvgen6OT8QbW_UifFFJGJBybTkJQ,1835
|
83
|
+
atk_common-3.6.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
|
84
84
|
atk_package/__init__.py,sha256=okIFEefQhQrw6DZg6oCEVWsEdkVCk-57VXBW0IUG_wU,834
|
85
85
|
atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
|
86
86
|
atk_package/env_utils.py,sha256=bXOrxM3fZUslqfmZt75iphbEJHbG4riJa8XOVzPwIII,313
|
@@ -93,7 +93,7 @@ atk_package/enums/__init__.py,sha256=EtUr_--MQj1Rc_R0sF_ELXIThmhpfmhDWq3YaK9oQMk
|
|
93
93
|
atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
|
94
94
|
atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
|
95
95
|
shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
96
|
-
atk_common-3.
|
97
|
-
atk_common-3.
|
98
|
-
atk_common-3.
|
99
|
-
atk_common-3.
|
96
|
+
atk_common-3.6.0.dist-info/METADATA,sha256=bmh0DRmR1XtoFrz7xMhG4wbtMjN7I5W8LX0fm1KVW7o,1760
|
97
|
+
atk_common-3.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
98
|
+
atk_common-3.6.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
|
99
|
+
atk_common-3.6.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|