sharedkernel 2.5.5__tar.gz → 2.5.7__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.
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/PKG-INFO +6 -1
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/README.md +4 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/setup.py +3 -2
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/config.py +1 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/distributed_cache.py +1 -1
- sharedkernel-2.5.7/sharedkernel/database/mongo_health_checker.py +67 -0
- sharedkernel-2.5.7/sharedkernel/enum/__init__.py +2 -0
- sharedkernel-2.5.7/sharedkernel/enum/redis_mode_enum.py +8 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/logger_service.py +62 -4
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel.egg-info/PKG-INFO +6 -1
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel.egg-info/SOURCES.txt +2 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel.egg-info/requires.txt +1 -0
- sharedkernel-2.5.5/sharedkernel/enum/__init__.py +0 -1
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/setup.cfg +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/common.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/data_format_converter.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/__init__.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/audit_model.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/mongo_generic_audit_repository.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/mongo_generic_repository.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/pagination_response_dto.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/date_converter.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/diff_utils.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/enum/error_code.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/enum/sort_order.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/file_validation.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/ip_session_service.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/log_decorator.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/log_dto.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/log_enums.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/log_info.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/logger/log_middlewares.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/multipart_upload.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/normalizer/__init__.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/normalizer/number_normalizer.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/normalizer/string_normalizer.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/base_document.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/json_string_model.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/result.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/objects/user_info.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/s3_uploader.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.7
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -21,6 +21,7 @@ Requires-Dist: beautifulsoup4
|
|
|
21
21
|
Requires-Dist: deepdiff
|
|
22
22
|
Requires-Dist: kombu
|
|
23
23
|
Requires-Dist: redis
|
|
24
|
+
Requires-Dist: pymongo
|
|
24
25
|
Dynamic: author
|
|
25
26
|
Dynamic: description
|
|
26
27
|
Dynamic: description-content-type
|
|
@@ -31,6 +32,10 @@ Dynamic: summary
|
|
|
31
32
|
this is a shared kernel package
|
|
32
33
|
|
|
33
34
|
# Change Log
|
|
35
|
+
### Version 2.5.7
|
|
36
|
+
- Add Database Health Check
|
|
37
|
+
### Version 2.5.6
|
|
38
|
+
- fix bug
|
|
34
39
|
### Version 2.5.5
|
|
35
40
|
- fix bug
|
|
36
41
|
### Version 2.5.4
|
|
@@ -37,10 +37,11 @@ setup(
|
|
|
37
37
|
"beautifulsoup4",
|
|
38
38
|
"deepdiff",
|
|
39
39
|
"kombu",
|
|
40
|
-
"redis"
|
|
40
|
+
"redis",
|
|
41
|
+
"pymongo"
|
|
41
42
|
],
|
|
42
43
|
# *strongly* suggested for sharing
|
|
43
|
-
version="2.5.
|
|
44
|
+
version="2.5.7",
|
|
44
45
|
description="sharekernel is a shared package between all python projects",
|
|
45
46
|
long_description=long_description,
|
|
46
47
|
long_description_content_type="text/markdown",
|
|
@@ -10,6 +10,7 @@ LOG_EXCHANGE = os.getenv("LOG_EXCHANGE")
|
|
|
10
10
|
LOG_REQUESTS_QUEUE = os.getenv("LOG_REQUESTS_QUEUE")
|
|
11
11
|
SERVICE_NAME = os.getenv("SERVICE_NAME")
|
|
12
12
|
IP_HEADER_NAME = os.getenv("IP_HEADER_NAME")
|
|
13
|
+
DB_HEALTH_CHECK_INTERVAL = int(os.getenv("DB_HEALTH_CHECK_INTERVAL", 15))
|
|
13
14
|
|
|
14
15
|
# IP Session ************************************************************************
|
|
15
16
|
IP_SESSION_AUTH_ENABLE = True if os.getenv("IP_SESSION_AUTH_ENABLE", "False").lower() == "true" else False
|
|
@@ -8,7 +8,7 @@ from redis.cluster import RedisCluster, ClusterNode
|
|
|
8
8
|
from sharedkernel.exception.exception import BusinessException
|
|
9
9
|
|
|
10
10
|
from sharedkernel import config
|
|
11
|
-
from
|
|
11
|
+
from sharedkernel.enum import ErrorCode, RedisMode
|
|
12
12
|
|
|
13
13
|
T = TypeVar("T", bound=BaseModel)
|
|
14
14
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import threading
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
from pymongo.errors import PyMongoError
|
|
5
|
+
|
|
6
|
+
from sharedkernel import config
|
|
7
|
+
|
|
8
|
+
class MongoHealthChecker:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
client,
|
|
12
|
+
interval: int = config.DB_HEALTH_CHECK_INTERVAL,
|
|
13
|
+
on_connect: Optional[Callable[[], None]] = None,
|
|
14
|
+
on_disconnect: Optional[Callable[[Exception], None]] = None,
|
|
15
|
+
):
|
|
16
|
+
|
|
17
|
+
self.client = client
|
|
18
|
+
self.interval = interval
|
|
19
|
+
self.on_connect = on_connect
|
|
20
|
+
self.on_disconnect = on_disconnect
|
|
21
|
+
|
|
22
|
+
self._is_connected = None
|
|
23
|
+
self._thread = None
|
|
24
|
+
self._stop_event = threading.Event()
|
|
25
|
+
|
|
26
|
+
def _default_on_connect(self):
|
|
27
|
+
print(f"Mongo connected")
|
|
28
|
+
|
|
29
|
+
def _default_on_disconnect(self, error):
|
|
30
|
+
print(f"Mongo DISCONNECTED: {error}")
|
|
31
|
+
|
|
32
|
+
def _run(self):
|
|
33
|
+
db = self.client.admin
|
|
34
|
+
|
|
35
|
+
while not self._stop_event.is_set():
|
|
36
|
+
try:
|
|
37
|
+
db.command("ping")
|
|
38
|
+
|
|
39
|
+
if self._is_connected is not True:
|
|
40
|
+
(self.on_connect or self._default_on_connect)()
|
|
41
|
+
self._is_connected = True
|
|
42
|
+
|
|
43
|
+
except PyMongoError as e:
|
|
44
|
+
if self._is_connected is not False:
|
|
45
|
+
(self.on_disconnect or self._default_on_disconnect)()
|
|
46
|
+
self._is_connected = False
|
|
47
|
+
|
|
48
|
+
time.sleep(self.interval)
|
|
49
|
+
|
|
50
|
+
def start(self):
|
|
51
|
+
if self._thread and self._thread.is_alive():
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
self._stop_event.clear()
|
|
55
|
+
|
|
56
|
+
self._thread = threading.Thread(
|
|
57
|
+
target=self._run,
|
|
58
|
+
daemon=True
|
|
59
|
+
)
|
|
60
|
+
self._thread.start()
|
|
61
|
+
|
|
62
|
+
def stop(self):
|
|
63
|
+
if not self._thread:
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
self._stop_event.set()
|
|
67
|
+
self._thread.join()
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from fastapi import HTTPException, WebSocket
|
|
2
2
|
from kombu import Connection, Producer, Exchange
|
|
3
|
+
from pymongo import monitoring
|
|
3
4
|
from pydantic import BaseModel
|
|
4
5
|
from typing import Optional
|
|
5
6
|
import datetime
|
|
6
7
|
import uuid
|
|
8
|
+
import os
|
|
7
9
|
|
|
8
10
|
from sharedkernel.logger.log_info import log_info
|
|
9
11
|
from sharedkernel.enum import ErrorCode
|
|
@@ -11,6 +13,7 @@ from sharedkernel.objects.user_info import current_user_info
|
|
|
11
13
|
from sharedkernel.exception.exception import BusinessException
|
|
12
14
|
from sharedkernel.logger.log_dto import LogDTO
|
|
13
15
|
from sharedkernel.logger.log_enums import LogEventTypeEnum, LogLevelEnum
|
|
16
|
+
from sharedkernel.database.mongo_health_checker import MongoHealthChecker
|
|
14
17
|
from sharedkernel import config
|
|
15
18
|
|
|
16
19
|
|
|
@@ -19,11 +22,13 @@ rabbitmq_url = (
|
|
|
19
22
|
f"@{config.RABBITMQ_HOST}/{config.RABBITMQ_VHOST}"
|
|
20
23
|
)
|
|
21
24
|
|
|
25
|
+
|
|
22
26
|
class LoggerService:
|
|
23
27
|
def __init__(self):
|
|
24
28
|
self._connection: Optional[Connection] = None
|
|
25
29
|
self._producer: Optional[Producer] = None
|
|
26
30
|
self._exchange = Exchange(config.LOG_EXCHANGE, type="topic")
|
|
31
|
+
self.checker: Optional[MongoHealthChecker] = None
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
def _ensure_connection(self):
|
|
@@ -51,10 +56,10 @@ class LoggerService:
|
|
|
51
56
|
|
|
52
57
|
def build(
|
|
53
58
|
self,
|
|
54
|
-
method_name: str,
|
|
55
|
-
event_type: LogEventTypeEnum,
|
|
56
|
-
endpoint_name: str = None,
|
|
57
|
-
is_success: bool = True,
|
|
59
|
+
method_name: Optional[str] = None,
|
|
60
|
+
event_type: Optional[LogEventTypeEnum] = None,
|
|
61
|
+
endpoint_name: Optional[str] = None,
|
|
62
|
+
is_success: Optional[bool] = True,
|
|
58
63
|
failure_reason: Optional[str] = None,
|
|
59
64
|
) -> LogDTO:
|
|
60
65
|
|
|
@@ -147,3 +152,56 @@ class LoggerService:
|
|
|
147
152
|
)
|
|
148
153
|
|
|
149
154
|
log_info.set(log_obj)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def set_log_to_context(self, correlation_id: str = None):
|
|
158
|
+
|
|
159
|
+
if not config.LOG_ENABLE:
|
|
160
|
+
return
|
|
161
|
+
|
|
162
|
+
log_obj = LogDTO(CorrelationId=correlation_id)
|
|
163
|
+
log_info.set(log_obj)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _on_mongo_connect(self):
|
|
167
|
+
self.set_log_to_context(correlation_id=uuid.uuid4().hex)
|
|
168
|
+
|
|
169
|
+
log = self.build(
|
|
170
|
+
method_name="mongo_health_check",
|
|
171
|
+
event_type=LogEventTypeEnum.START,
|
|
172
|
+
endpoint_name="اتصال به دیتابیس",
|
|
173
|
+
is_success=True,
|
|
174
|
+
)
|
|
175
|
+
self.emit(log)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _on_mongo_disconnect(self):
|
|
179
|
+
log = self.build(
|
|
180
|
+
method_name="mongo_health_check",
|
|
181
|
+
event_type=LogEventTypeEnum.END,
|
|
182
|
+
endpoint_name="قطع اتصال به دیتابیس",
|
|
183
|
+
is_success=False,
|
|
184
|
+
)
|
|
185
|
+
self.emit(log)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def start_db_logger(self, db_client):
|
|
189
|
+
if not config.LOG_ENABLE:
|
|
190
|
+
return
|
|
191
|
+
|
|
192
|
+
self.checker = MongoHealthChecker(
|
|
193
|
+
db_client,
|
|
194
|
+
on_connect=self._on_mongo_connect,
|
|
195
|
+
on_disconnect=self._on_mongo_disconnect,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
self.checker.start()
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def stop_db_logger(self):
|
|
202
|
+
if not config.LOG_ENABLE:
|
|
203
|
+
return
|
|
204
|
+
|
|
205
|
+
if self.checker:
|
|
206
|
+
self.checker.stop()
|
|
207
|
+
self.checker = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.7
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -21,6 +21,7 @@ Requires-Dist: beautifulsoup4
|
|
|
21
21
|
Requires-Dist: deepdiff
|
|
22
22
|
Requires-Dist: kombu
|
|
23
23
|
Requires-Dist: redis
|
|
24
|
+
Requires-Dist: pymongo
|
|
24
25
|
Dynamic: author
|
|
25
26
|
Dynamic: description
|
|
26
27
|
Dynamic: description-content-type
|
|
@@ -31,6 +32,10 @@ Dynamic: summary
|
|
|
31
32
|
this is a shared kernel package
|
|
32
33
|
|
|
33
34
|
# Change Log
|
|
35
|
+
### Version 2.5.7
|
|
36
|
+
- Add Database Health Check
|
|
37
|
+
### Version 2.5.6
|
|
38
|
+
- fix bug
|
|
34
39
|
### Version 2.5.5
|
|
35
40
|
- fix bug
|
|
36
41
|
### Version 2.5.4
|
|
@@ -22,9 +22,11 @@ sharedkernel/database/audit_model.py
|
|
|
22
22
|
sharedkernel/database/distributed_cache.py
|
|
23
23
|
sharedkernel/database/mongo_generic_audit_repository.py
|
|
24
24
|
sharedkernel/database/mongo_generic_repository.py
|
|
25
|
+
sharedkernel/database/mongo_health_checker.py
|
|
25
26
|
sharedkernel/database/pagination_response_dto.py
|
|
26
27
|
sharedkernel/enum/__init__.py
|
|
27
28
|
sharedkernel/enum/error_code.py
|
|
29
|
+
sharedkernel/enum/redis_mode_enum.py
|
|
28
30
|
sharedkernel/enum/sort_order.py
|
|
29
31
|
sharedkernel/exception/__init__.py
|
|
30
32
|
sharedkernel/exception/exception.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .error_code import ErrorCode
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/database/mongo_generic_audit_repository.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-2.5.5 → sharedkernel-2.5.7}/sharedkernel/normalizer/phone_number_normalizer.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|