internal 1.0.69__tar.gz → 1.0.71__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.
Potentially problematic release.
This version of internal might be problematic. Click here for more details.
- {internal-1.0.69 → internal-1.0.71}/PKG-INFO +2 -1
- {internal-1.0.69 → internal-1.0.71}/pyproject.toml +2 -1
- {internal-1.0.69 → internal-1.0.71}/src/internal/base_config.py +3 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/base_factory.py +10 -7
- internal-1.0.71/src/internal/cache_redis.py +23 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/exception/internal_exception.py +18 -0
- {internal-1.0.69 → internal-1.0.71}/README.md +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/contact_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/description_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/event_trigger_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/feature.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/lpnr_direction.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/notify_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/operator_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/common_enum/order_type.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/const.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/database.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/exception/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/exception/app_exception.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/exception/base_exception.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/ext/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/ext/amazon/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/ext/amazon/aws/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/ext/amazon/aws/const.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/http/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/http/requests.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/http/responses.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/interface/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/interface/base_interface.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/middleware/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/middleware/log_request.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/model/__init__.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/model/base_model.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/model/operate.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/utils.py +0 -0
- {internal-1.0.69 → internal-1.0.71}/src/internal/validator_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: internal
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.71
|
|
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,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "internal"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.71"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["Ray <ray@cruisys.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -15,6 +15,7 @@ watchtower = "^3.0.1"
|
|
|
15
15
|
httpx = "^0.26.0"
|
|
16
16
|
beanie = "^1.24.0"
|
|
17
17
|
dictdiffer = "^0.9.0"
|
|
18
|
+
redis = "^5.1.1"
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
[build-system]
|
|
@@ -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
|
|
@@ -40,11 +40,14 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
40
40
|
Each factory should define what model it wants.
|
|
41
41
|
"""
|
|
42
42
|
|
|
43
|
-
@abstractmethod
|
|
44
43
|
async def init_state_cache(self, app, app_config):
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
if app_config.REDIS_URL:
|
|
45
|
+
redis_cache = cache_redis.CacheRedis(app_config.REDIS_URL)
|
|
46
|
+
await redis_cache.connect()
|
|
47
|
+
app.state.redis = redis_cache.client
|
|
48
|
+
app.state.logger.info("Initialization state cache done")
|
|
49
|
+
else:
|
|
50
|
+
app.state.logger.info("skip initialization state cache")
|
|
48
51
|
|
|
49
52
|
async def init_state_scheduler_app(self, app, app_config):
|
|
50
53
|
"""
|
|
@@ -69,7 +72,6 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
69
72
|
await init_beanie(database=app.state.db.get_database(), document_models=document_model_list)
|
|
70
73
|
app.state.logger.info("Database connected")
|
|
71
74
|
await self.init_state_cache(app, self.get_app_config())
|
|
72
|
-
app.state.logger.info("Initialization state cache done")
|
|
73
75
|
await self.init_state_scheduler_app(app, self.get_app_config())
|
|
74
76
|
app.state.logger.info("Initialization state scheduler app done")
|
|
75
77
|
|
|
@@ -77,7 +79,8 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
77
79
|
# code to execute when app is shutting down
|
|
78
80
|
await mongodb.close()
|
|
79
81
|
app.state.logger.info("Database disconnected")
|
|
80
|
-
|
|
82
|
+
await app.state.redis.close()
|
|
83
|
+
app.state.logger.info("Cache disconnected")
|
|
81
84
|
|
|
82
85
|
if title is None:
|
|
83
86
|
title = self.DEFAULT_APP_NAME
|
|
@@ -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)
|
|
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
|
|
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
|