atk-common 0.2.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.
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: atk_common
3
+ Version: 0.2.0
4
+ Summary: ATK common methods
5
+ Home-page: https://github.com/pypa/atk_common
6
+ Author: Roger
7
+ Author-email: roger@perspic.tech
8
+ Project-URL: Bug Reports, https://github.com/pypa/atk_common/issues
9
+ Project-URL: Funding, https://donate.pypi.org
10
+ Project-URL: Say Thanks!, http://saythanks.io/to/example
11
+ Project-URL: Source, https://github.com/pypa/atk_common/
12
+ Keywords: sample,setuptools,development
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Build Tools
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: license.txt
26
+ Requires-Dist: kombu>=5.4.2
27
+ Requires-Dist: requests>=2.32.3
28
+
29
+ This package contains atk enforcement common entities and components
@@ -0,0 +1,10 @@
1
+ atk_package/__init__.py,sha256=O1j-hzo4WkOwhZlDDacYPvrpWIURgebb03GTuldPwuI,180
2
+ atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
3
+ atk_package/log_utils.py,sha256=u-8fkV_cDlVWG-N3ZfqGOPgC-S4dfSJEgyhdc9XDKmo,439
4
+ atk_package/rabbitmq_consumer.py,sha256=wmZQieeONkfXB5RmM6yiNkwl0_QK4oWWDBSfiD47CdA,1753
5
+ shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ atk_common-0.2.0.dist-info/METADATA,sha256=MR4KaRNZdL4yOLymWsgO4N1_oQ3JamFE8ebCwZlSMMk,1193
7
+ atk_common-0.2.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ atk_common-0.2.0.dist-info/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
9
+ atk_common-0.2.0.dist-info/top_level.txt,sha256=4HLkJ8mtbeZikG_9tMb5-dw9UWuAQk3xUN_izlisloQ,42
10
+ atk_common-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Perspic AS
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ atk_package
2
+ shared_python_atk_enforcement
@@ -0,0 +1,4 @@
1
+ # __init__.py
2
+ from .rabbitmq_consumer import RabbitMQConsumer
3
+ from .datetime_utils import date_time_utc, get_utc_date_time
4
+ from .log_utils import add_log_item, add_log_item_http
@@ -0,0 +1,7 @@
1
+ from datetime import datetime, timezone
2
+
3
+ def date_time_utc(column):
4
+ return 'TO_CHAR({0} at time zone \'UTC\', \'yyyy-mm-dd hh24:mi:ss.ms"Z"\')'.format(column)
5
+
6
+ def get_utc_date_time():
7
+ return str(datetime.now(timezone.utc))
@@ -0,0 +1,16 @@
1
+ from datetime import datetime
2
+ from datetime_utils import get_utc_date_time
3
+
4
+ def create_date_time():
5
+ date_time = get_utc_date_time()
6
+ return '[' + date_time + '] '
7
+
8
+ def add_log_item(text):
9
+ print(create_date_time() + text)
10
+
11
+ def add_log_item_http(resp):
12
+ if resp.status_code == 500:
13
+ err_resp_json = resp.json().get('message')
14
+ add_log_item(err_resp_json)
15
+ else:
16
+ add_log_item(resp.text)
@@ -0,0 +1,49 @@
1
+ from kombu import Connection, Exchange, Queue, Consumer
2
+ import socket
3
+ import time
4
+
5
+ class RabbitMQConsumer:
6
+ def __init__(self, queue_name, user, pwd, host, vhost, dlx, dlq, encoding, message_handler, log):
7
+
8
+ rabbit_url = 'amqp://' + user + ':' + pwd + '@' + host + '/' + vhost
9
+
10
+ self.connection = Connection(rabbit_url, heartbeat=10)
11
+ queue = None
12
+ if dlx is not None and dlq is not None:
13
+ queue = Queue(name=queue_name,
14
+ queue_arguments={
15
+ 'x-dead-letter-exchange': dlx,
16
+ 'x-dead-letter-routing-key': dlq},
17
+ )
18
+ else:
19
+ queue = Queue(name=queue_name)
20
+ self.consumer = Consumer(self.connection, queues=queue, callbacks=[message_handler], accept=[encoding])
21
+ self.consumer.consume()
22
+
23
+ self.message_handler = message_handler # Custom message handler
24
+ self.log = log
25
+
26
+ def consume(self):
27
+ new_conn = self.establish_connection()
28
+ while True:
29
+ try:
30
+ new_conn.drain_events(timeout=2)
31
+ except socket.timeout:
32
+ new_conn.heartbeat_check()
33
+
34
+ def establish_connection(self):
35
+ revived_connection = self.connection.clone()
36
+ revived_connection.ensure_connection(max_retries=3)
37
+ channel = revived_connection.channel()
38
+ self.consumer.revive(channel)
39
+ self.consumer.consume()
40
+ self.log("Connection revived!")
41
+ return revived_connection
42
+
43
+ def run(self):
44
+ while True:
45
+ try:
46
+ self.consume()
47
+ except self.connection.connection_errors:
48
+ pass
49
+
File without changes