atk-common 1.60.0__py3-none-any.whl → 1.62.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/__init__.py +4 -0
- atk_common/consumer_retry_handler.py +49 -0
- atk_common/default_should_retry.py +19 -0
- atk_common/env_utils.py +11 -2
- {atk_common-1.60.0.dist-info → atk_common-1.62.0.dist-info}/METADATA +1 -1
- {atk_common-1.60.0.dist-info → atk_common-1.62.0.dist-info}/RECORD +9 -7
- {atk_common-1.60.0.dist-info → atk_common-1.62.0.dist-info}/WHEEL +0 -0
- {atk_common-1.60.0.dist-info → atk_common-1.62.0.dist-info}/licenses/license.txt +0 -0
- {atk_common-1.60.0.dist-info → atk_common-1.62.0.dist-info}/top_level.txt +0 -0
atk_common/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# __init__.py
|
2
|
+
from atk_common.consumer_retry_handler import create_retry_handler
|
2
3
|
from atk_common.datetime_utils import \
|
3
4
|
get_utc_date_time, \
|
4
5
|
get_utc_date_time_str, \
|
@@ -9,6 +10,7 @@ from atk_common.datetime_utils import \
|
|
9
10
|
convert_to_utc, \
|
10
11
|
convert_to_utc_image_dt
|
11
12
|
from atk_common.db_utils import sql, sql_with_record, convert_none_to_null, date_time_utc_column
|
13
|
+
from atk_common.default_should_retry import default_should_retry
|
12
14
|
from atk_common.docker_utils import get_current_container_info, set_container_metadata
|
13
15
|
from atk_common.env_utils import get_env_value
|
14
16
|
from atk_common.error_utils import get_message, create_error_log, get_error_entity, resend_error_entity, handle_error, get_response_error, get_error_type
|
@@ -22,6 +24,7 @@ from atk_common.mq_utils import decode_message
|
|
22
24
|
from atk_common.rabbitmq_consumer import RabbitMQConsumer
|
23
25
|
|
24
26
|
__all__ = [
|
27
|
+
'create_retry_handler',
|
25
28
|
'get_utc_date_time',
|
26
29
|
'get_utc_date_time_str',
|
27
30
|
'get_utc_date_time_str_with_z',
|
@@ -34,6 +37,7 @@ __all__ = [
|
|
34
37
|
'sql_with_record',
|
35
38
|
'convert_none_to_null',
|
36
39
|
'date_time_utc_column',
|
40
|
+
'default_should_retry',
|
37
41
|
'get_current_container_info',
|
38
42
|
'set_container_metadata',
|
39
43
|
'get_env_value',
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from kombu import Producer
|
2
|
+
from atk_common import *
|
3
|
+
|
4
|
+
def create_retry_handler(process_func, connection, exchange, routing_key, should_retry, log, declare=None):
|
5
|
+
"""
|
6
|
+
process_func: your original handler function (body, message)
|
7
|
+
retry_queue: kombu.Queue instance to republish to
|
8
|
+
should_retry: function(message_status) -> bool
|
9
|
+
log: function for logging
|
10
|
+
"""
|
11
|
+
|
12
|
+
def handler(body, message):
|
13
|
+
try:
|
14
|
+
process_response = process_func(body, message)
|
15
|
+
if is_response_ok(process_response):
|
16
|
+
message.ack()
|
17
|
+
else:
|
18
|
+
if connection is not None:
|
19
|
+
# Use retry queue
|
20
|
+
if should_retry(process_response):
|
21
|
+
log("Retrying after delay...")
|
22
|
+
with connection.Producer() as producer:
|
23
|
+
producer.publish(
|
24
|
+
message.body,
|
25
|
+
exchange=exchange,
|
26
|
+
routing_key=routing_key,
|
27
|
+
retry=True,
|
28
|
+
declare=declare,
|
29
|
+
content_type=message.content_type,
|
30
|
+
content_encoding=message.content_encoding,
|
31
|
+
headers=message.headers,
|
32
|
+
timestamp=message.properties.get("timestamp")
|
33
|
+
)
|
34
|
+
message.ack()
|
35
|
+
else:
|
36
|
+
log("Sending to DLQ...")
|
37
|
+
message.reject(requeue=False)
|
38
|
+
else:
|
39
|
+
if should_retry(process_response):
|
40
|
+
log("Requing...")
|
41
|
+
message.requeue()
|
42
|
+
else:
|
43
|
+
log("Sending to DLQ...")
|
44
|
+
message.reject(requeue=False)
|
45
|
+
except Exception as e:
|
46
|
+
log(f"Error during processing: {e}")
|
47
|
+
message.reject(requeue=False)
|
48
|
+
|
49
|
+
return handler
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from atk_common.enums.api_error_type_enum import ApiErrorType
|
2
|
+
from atk_common.enums.response_status_type_enum import ResponseStatusType
|
3
|
+
from atk_common.http_utils import is_http_status_internal, is_http_status_ok
|
4
|
+
|
5
|
+
def default_should_retry(message_status):
|
6
|
+
if message_status['status'] == ResponseStatusType.HTTP:
|
7
|
+
status_code = message_status['statusCode']
|
8
|
+
if is_http_status_ok(status_code):
|
9
|
+
return False
|
10
|
+
elif is_http_status_internal(status_code):
|
11
|
+
#errorType = 1: connection error
|
12
|
+
#errorType = 2: api internal error (database, etc)
|
13
|
+
if message_status['responseMsg']['errorType'] == ApiErrorType.CONNECTION.value:
|
14
|
+
return True
|
15
|
+
else:
|
16
|
+
return False
|
17
|
+
else:
|
18
|
+
return True
|
19
|
+
return True
|
atk_common/env_utils.py
CHANGED
@@ -3,16 +3,25 @@ from atk_common.log_utils import add_log_item
|
|
3
3
|
|
4
4
|
def val_str(value):
|
5
5
|
if value is None:
|
6
|
-
return 'Empty'
|
6
|
+
return '<Empty>'
|
7
7
|
if isinstance(value, str):
|
8
|
+
if value.strip() == '' or value.lower() == 'null':
|
9
|
+
return '<Null>'
|
8
10
|
return value
|
9
11
|
return str(value)
|
10
12
|
|
13
|
+
def is_value_null_or_empty(value):
|
14
|
+
if isinstance(value, str):
|
15
|
+
return value.strip() == '' or value.lower() == 'null'
|
16
|
+
return False
|
17
|
+
|
11
18
|
def get_env_value(key, abort_on_error=True):
|
12
19
|
val = os.environ.get(key)
|
20
|
+
add_log_item(key + ':' + val_str(val))
|
13
21
|
if val is None and abort_on_error:
|
14
22
|
err_msg = f"Environment variable '{key}' is not set."
|
15
23
|
add_log_item(err_msg)
|
16
24
|
raise ValueError(err_msg)
|
17
|
-
|
25
|
+
if is_value_null_or_empty(val):
|
26
|
+
return None
|
18
27
|
return val
|
@@ -1,8 +1,10 @@
|
|
1
|
-
atk_common/__init__.py,sha256=
|
1
|
+
atk_common/__init__.py,sha256=LHe1sm1n2yVpgtQ2Akjf75UM_0QtdqQyOwuC8jDwsdA,2405
|
2
|
+
atk_common/consumer_retry_handler.py,sha256=Djig-DIh0FeL_vKWkWg05dAxI8y991kNipQDrhKKBxQ,2082
|
2
3
|
atk_common/datetime_utils.py,sha256=0SC5-Nai4RJH9B0VzvGKUQts_QeRXGb7tJLlsh73LJw,3556
|
3
4
|
atk_common/db_utils.py,sha256=odUtXcS7Mumw5eGyVyVimL_U_lP7TqMX9v8nWO5nMvg,902
|
5
|
+
atk_common/default_should_retry.py,sha256=lchNA42vnB0qz26BlNA-be05p2eKv_34E6qaRce5trU,832
|
4
6
|
atk_common/docker_utils.py,sha256=Z7BGCV5IX-O38jLSTDBN8k617zMsYDHL3VWdhoBXVfs,2504
|
5
|
-
atk_common/env_utils.py,sha256=
|
7
|
+
atk_common/env_utils.py,sha256=VCXEaAEGWFdQr5x7pKmks1Xs_g6gyrcwikqSz2XfETo,813
|
6
8
|
atk_common/error_utils.py,sha256=kO-VQlajD8SO9MBxj8MHZRTK_uBXgPa09hy6pfjqZBY,2622
|
7
9
|
atk_common/file_utils.py,sha256=UDwcRquO9IrqRrlUM0t-_g4R1-FKt8ZqQinSEqXOAk8,112
|
8
10
|
atk_common/hash_utils.py,sha256=S_9o89CdI4lUQbVaqc85TDcqyDNuo30_E3VBaOrZKko,1047
|
@@ -52,7 +54,7 @@ atk_common/enums/speed_control_status_type_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe
|
|
52
54
|
atk_common/enums/speed_control_stop_reason.py,sha256=pvLS6fpDhsCiIDAmiQBsHctxZnq-Dl2BOgJOxQnT5Hc,200
|
53
55
|
atk_common/enums/test_image_type_enum.py,sha256=HUjxJorehnzRXMNF2uHk2DrAJ3Y_ajQvp0jW-mtlOhU,140
|
54
56
|
atk_common/enums/violation_type_enum.py,sha256=01qTHOj-O8bOc-nwIHVnxLosm4cusD_YuqXM3ZsiRRk,86
|
55
|
-
atk_common-1.
|
57
|
+
atk_common-1.62.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
|
56
58
|
atk_package/__init__.py,sha256=NcsmwFadivgIeWV0-5ACZxqmfo4EzTkJX0r4N6DFAdg,820
|
57
59
|
atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
|
58
60
|
atk_package/env_utils.py,sha256=bXOrxM3fZUslqfmZt75iphbEJHbG4riJa8XOVzPwIII,313
|
@@ -65,7 +67,7 @@ atk_package/enums/__init__.py,sha256=EtUr_--MQj1Rc_R0sF_ELXIThmhpfmhDWq3YaK9oQMk
|
|
65
67
|
atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
|
66
68
|
atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
|
67
69
|
shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
68
|
-
atk_common-1.
|
69
|
-
atk_common-1.
|
70
|
-
atk_common-1.
|
71
|
-
atk_common-1.
|
70
|
+
atk_common-1.62.0.dist-info/METADATA,sha256=SEWkaeUOb9aoCN30qkFooGj8-xySUhomLX6BW3hsyqs,1761
|
71
|
+
atk_common-1.62.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
72
|
+
atk_common-1.62.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
|
73
|
+
atk_common-1.62.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|