internal 1.0.68__tar.gz → 1.0.70__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.

Files changed (38) hide show
  1. {internal-1.0.68 → internal-1.0.70}/PKG-INFO +2 -1
  2. {internal-1.0.68 → internal-1.0.70}/pyproject.toml +2 -1
  3. {internal-1.0.68 → internal-1.0.70}/src/internal/base_config.py +3 -0
  4. {internal-1.0.68 → internal-1.0.70}/src/internal/base_factory.py +7 -4
  5. internal-1.0.70/src/internal/cache_redis.py +23 -0
  6. {internal-1.0.68 → internal-1.0.70}/src/internal/exception/app_exception.py +1 -1
  7. {internal-1.0.68 → internal-1.0.70}/src/internal/exception/internal_exception.py +18 -0
  8. {internal-1.0.68 → internal-1.0.70}/README.md +0 -0
  9. {internal-1.0.68 → internal-1.0.70}/src/internal/__init__.py +0 -0
  10. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/__init__.py +0 -0
  11. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/contact_type.py +0 -0
  12. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/description_type.py +0 -0
  13. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/event_trigger_type.py +0 -0
  14. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/feature.py +0 -0
  15. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/lpnr_direction.py +0 -0
  16. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/notify_type.py +0 -0
  17. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/operator_type.py +0 -0
  18. {internal-1.0.68 → internal-1.0.70}/src/internal/common_enum/order_type.py +0 -0
  19. {internal-1.0.68 → internal-1.0.70}/src/internal/const.py +0 -0
  20. {internal-1.0.68 → internal-1.0.70}/src/internal/database.py +0 -0
  21. {internal-1.0.68 → internal-1.0.70}/src/internal/exception/__init__.py +0 -0
  22. {internal-1.0.68 → internal-1.0.70}/src/internal/exception/base_exception.py +0 -0
  23. {internal-1.0.68 → internal-1.0.70}/src/internal/ext/__init__.py +0 -0
  24. {internal-1.0.68 → internal-1.0.70}/src/internal/ext/amazon/__init__.py +0 -0
  25. {internal-1.0.68 → internal-1.0.70}/src/internal/ext/amazon/aws/__init__.py +0 -0
  26. {internal-1.0.68 → internal-1.0.70}/src/internal/ext/amazon/aws/const.py +0 -0
  27. {internal-1.0.68 → internal-1.0.70}/src/internal/http/__init__.py +0 -0
  28. {internal-1.0.68 → internal-1.0.70}/src/internal/http/requests.py +0 -0
  29. {internal-1.0.68 → internal-1.0.70}/src/internal/http/responses.py +0 -0
  30. {internal-1.0.68 → internal-1.0.70}/src/internal/interface/__init__.py +0 -0
  31. {internal-1.0.68 → internal-1.0.70}/src/internal/interface/base_interface.py +0 -0
  32. {internal-1.0.68 → internal-1.0.70}/src/internal/middleware/__init__.py +0 -0
  33. {internal-1.0.68 → internal-1.0.70}/src/internal/middleware/log_request.py +0 -0
  34. {internal-1.0.68 → internal-1.0.70}/src/internal/model/__init__.py +0 -0
  35. {internal-1.0.68 → internal-1.0.70}/src/internal/model/base_model.py +0 -0
  36. {internal-1.0.68 → internal-1.0.70}/src/internal/model/operate.py +0 -0
  37. {internal-1.0.68 → internal-1.0.70}/src/internal/utils.py +0 -0
  38. {internal-1.0.68 → internal-1.0.70}/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.68
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,6 @@
1
1
  [tool.poetry]
2
2
  name = "internal"
3
- version = "1.0.68"
3
+ version = "1.0.70"
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]
@@ -58,5 +58,8 @@ class BaseConfig(BaseSettings):
58
58
  SYSTEM_BRAND: str = "cruisys"
59
59
  SYSTEM_ORGANIZATION_ID: str = "cruisys"
60
60
 
61
+ # Redis URL
62
+ REDIS_URL: str = ""
63
+
61
64
  class Config:
62
65
  case_sensitive = False
@@ -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
- Each factory should define what model it wants.
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:
@@ -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()
@@ -49,7 +49,7 @@ class PlateNoFormatException(InternalBaseException):
49
49
 
50
50
  class VinLengthOrFormatException(InternalBaseException):
51
51
  code = "error_vin_length_or_format"
52
- message = "VIN only allow alphanumeric 7 or 17 characters"
52
+ message = "VIN only allow alphanumeric 7 or 10 or 17 characters"
53
53
 
54
54
  def __init__(self, message: str = None, **kwargs):
55
55
  _message = message or self.message
@@ -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