internal 1.0.69__py3-none-any.whl → 1.0.70__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.
Potentially problematic release.
This version of internal might be problematic. Click here for more details.
- internal/base_config.py +3 -0
- internal/base_factory.py +7 -4
- internal/cache_redis.py +23 -0
- internal/exception/internal_exception.py +18 -0
- {internal-1.0.69.dist-info → internal-1.0.70.dist-info}/METADATA +2 -1
- {internal-1.0.69.dist-info → internal-1.0.70.dist-info}/RECORD +7 -6
- {internal-1.0.69.dist-info → internal-1.0.70.dist-info}/WHEEL +0 -0
internal/base_config.py
CHANGED
internal/base_factory.py
CHANGED
|
@@ -13,7 +13,7 @@ from fastapi import FastAPI, status, Request, APIRouter
|
|
|
13
13
|
from fastapi.exceptions import RequestValidationError
|
|
14
14
|
from fastapi.middleware.cors import CORSMiddleware
|
|
15
15
|
|
|
16
|
-
from . import database
|
|
16
|
+
from . import database, cache_redis
|
|
17
17
|
from .const import LOG_FMT, LOG_FMT_NO_DT, LOG_DT_FMT, DEFAULT_LOGGER_NAME
|
|
18
18
|
from .exception.base_exception import InternalBaseException
|
|
19
19
|
from .exception.internal_exception import BadGatewayException, GatewayTimeoutException
|
|
@@ -42,9 +42,10 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
42
42
|
|
|
43
43
|
@abstractmethod
|
|
44
44
|
async def init_state_cache(self, app, app_config):
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if app_config.REDIS_URL:
|
|
46
|
+
redis_cache = cache_redis.CacheRedis(app_config.REDIS_URL)
|
|
47
|
+
await redis_cache.connect()
|
|
48
|
+
app.state.redis = redis_cache.client
|
|
48
49
|
|
|
49
50
|
async def init_state_scheduler_app(self, app, app_config):
|
|
50
51
|
"""
|
|
@@ -77,6 +78,8 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
77
78
|
# code to execute when app is shutting down
|
|
78
79
|
await mongodb.close()
|
|
79
80
|
app.state.logger.info("Database disconnected")
|
|
81
|
+
await app.state.redis.close()
|
|
82
|
+
app.state.logger.info("Cache disconnected")
|
|
80
83
|
|
|
81
84
|
|
|
82
85
|
if title is None:
|
internal/cache_redis.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import redis.asyncio as redis
|
|
2
|
+
|
|
3
|
+
from motor.motor_asyncio import AsyncIOMotorClient
|
|
4
|
+
from pymongo.errors import ServerSelectionTimeoutError
|
|
5
|
+
|
|
6
|
+
from .exception.internal_exception import RedisInitializeFailureException, RedisConnectFailureException
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CacheRedis:
|
|
10
|
+
def __init__(self, redis_url: str):
|
|
11
|
+
self.client = None
|
|
12
|
+
self.redis_url = redis_url
|
|
13
|
+
|
|
14
|
+
async def connect(self):
|
|
15
|
+
try:
|
|
16
|
+
connection_pool = redis.ConnectionPool.from_url(self.redis_url)
|
|
17
|
+
self.client = redis.Redis(connection_pool=connection_pool)
|
|
18
|
+
except Exception as e:
|
|
19
|
+
raise RedisInitializeFailureException()
|
|
20
|
+
|
|
21
|
+
async def close(self):
|
|
22
|
+
if self.client:
|
|
23
|
+
self.client.close()
|
|
@@ -63,3 +63,21 @@ class ParamValidationException(InternalBaseException):
|
|
|
63
63
|
def __init__(self, message: str = None, **kwargs):
|
|
64
64
|
_message = message or self.message
|
|
65
65
|
super().__init__(status.HTTP_422_UNPROCESSABLE_ENTITY, self.code, _message, **kwargs)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class RedisInitializeFailureException(InternalBaseException):
|
|
69
|
+
code = "error_redis_initialize"
|
|
70
|
+
message = "Redis initialize failure"
|
|
71
|
+
|
|
72
|
+
def __init__(self, message: str = None, **kwargs):
|
|
73
|
+
_message = message or self.message
|
|
74
|
+
super().__init__(status.HTTP_500_INTERNAL_SERVER_ERROR, self.code, _message, **kwargs)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class RedisConnectFailureException(InternalBaseException):
|
|
78
|
+
code = "error_redis_connect"
|
|
79
|
+
message = "Redis connect failure"
|
|
80
|
+
|
|
81
|
+
def __init__(self, message: str = None, **kwargs):
|
|
82
|
+
_message = message or self.message
|
|
83
|
+
super().__init__(status.HTTP_500_INTERNAL_SERVER_ERROR, self.code, _message, **kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: internal
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.70
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Ray
|
|
6
6
|
Author-email: ray@cruisys.com
|
|
@@ -14,6 +14,7 @@ Requires-Dist: dictdiffer (>=0.9.0,<0.10.0)
|
|
|
14
14
|
Requires-Dist: fastapi (>=0.109.0,<0.110.0)
|
|
15
15
|
Requires-Dist: httpx (>=0.26.0,<0.27.0)
|
|
16
16
|
Requires-Dist: pydantic-settings (>=2.1.0,<3.0.0)
|
|
17
|
+
Requires-Dist: redis (>=5.1.1,<6.0.0)
|
|
17
18
|
Requires-Dist: watchtower (>=3.0.1,<4.0.0)
|
|
18
19
|
Description-Content-Type: text/markdown
|
|
19
20
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
internal/base_config.py,sha256=
|
|
3
|
-
internal/base_factory.py,sha256=
|
|
2
|
+
internal/base_config.py,sha256=TykK9HNF9y3OcIBPgx0h3VfVW5XH7nClLReq1-cqZCg,1995
|
|
3
|
+
internal/base_factory.py,sha256=EtiGGe75QHkqIsUUw2LxjqwHWbzadUkjQV-FRJRAetI,10349
|
|
4
|
+
internal/cache_redis.py,sha256=Lh6gnLIMQi3Rdp4yaUxqgrN1ZCvmHtTQ1GTep0xqcrA,721
|
|
4
5
|
internal/common_enum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
6
|
internal/common_enum/contact_type.py,sha256=7QkTQ71UxpaT1YHI40FpjmLz3r-UbRU-sd0m5ajH1as,142
|
|
6
7
|
internal/common_enum/description_type.py,sha256=kGwkFQh6dMnjDl6ipWYpA-qbNRrhEpnPq3NleTsNwwk,118
|
|
@@ -15,7 +16,7 @@ internal/database.py,sha256=1u53JnFJ0jvP7H4HPY2faA2ABdPQ8SlsZigYmQAPktI,2470
|
|
|
15
16
|
internal/exception/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
17
|
internal/exception/app_exception.py,sha256=z7BGD0iw0VW5rczQb-sjnfxk1O_E6CPWMnBUfddU-0g,3467
|
|
17
18
|
internal/exception/base_exception.py,sha256=8ctp525A3up9mZrHCq_-Jj0hWr_4NfZsXGg1e4ftVuQ,473
|
|
18
|
-
internal/exception/internal_exception.py,sha256=
|
|
19
|
+
internal/exception/internal_exception.py,sha256=DDJg2tZtbcy4xlAhinJNzntSU1HcpGZ_XFP_perMzzo,2957
|
|
19
20
|
internal/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
21
|
internal/ext/amazon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
22
|
internal/ext/amazon/aws/__init__.py,sha256=2YFjb-rHG1JaZGZiZffYDesgTAJjDshOqQbswOYzhP8,834
|
|
@@ -32,6 +33,6 @@ internal/model/base_model.py,sha256=NS_GZvw_IqU1aZPHPpyQs6A741O34ybmzVzBPm9nGWU,
|
|
|
32
33
|
internal/model/operate.py,sha256=QSM6yXYXpJMwrqkUGEWZLrEBaUgqHwVHY_Fi4S42hKc,3190
|
|
33
34
|
internal/utils.py,sha256=CXYZs4rDDe33Zac27YeknBE4uQN437ys1YAbW3Xeyow,1517
|
|
34
35
|
internal/validator_utils.py,sha256=5ZLcNIgw1hvkYOj1f6gS9AYxe7Y3ufW9FyDxUS7FsMQ,1226
|
|
35
|
-
internal-1.0.
|
|
36
|
-
internal-1.0.
|
|
37
|
-
internal-1.0.
|
|
36
|
+
internal-1.0.70.dist-info/METADATA,sha256=SwTZzaFsrL2Ppva2YJW57pg86M5ND5xnvFT38bJVB3s,663
|
|
37
|
+
internal-1.0.70.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
38
|
+
internal-1.0.70.dist-info/RECORD,,
|
|
File without changes
|