internal 1.0.51__tar.gz → 1.0.53__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 (33) hide show
  1. {internal-1.0.51 → internal-1.0.53}/PKG-INFO +1 -1
  2. {internal-1.0.51 → internal-1.0.53}/pyproject.toml +1 -1
  3. {internal-1.0.51 → internal-1.0.53}/src/internal/base_factory.py +19 -0
  4. {internal-1.0.51 → internal-1.0.53}/src/internal/http/requests.py +9 -0
  5. {internal-1.0.51 → internal-1.0.53}/src/internal/model/operate.py +11 -0
  6. {internal-1.0.51 → internal-1.0.53}/README.md +0 -0
  7. {internal-1.0.51 → internal-1.0.53}/src/internal/__init__.py +0 -0
  8. {internal-1.0.51 → internal-1.0.53}/src/internal/base_config.py +0 -0
  9. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/__init__.py +0 -0
  10. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/contact_type.py +0 -0
  11. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/description_type.py +0 -0
  12. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/event_trigger_type.py +0 -0
  13. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/lpnr_direction.py +0 -0
  14. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/operator_type.py +0 -0
  15. {internal-1.0.51 → internal-1.0.53}/src/internal/common_enum/order_type.py +0 -0
  16. {internal-1.0.51 → internal-1.0.53}/src/internal/const.py +0 -0
  17. {internal-1.0.51 → internal-1.0.53}/src/internal/database.py +0 -0
  18. {internal-1.0.51 → internal-1.0.53}/src/internal/exception/__init__.py +0 -0
  19. {internal-1.0.51 → internal-1.0.53}/src/internal/exception/base_exception.py +0 -0
  20. {internal-1.0.51 → internal-1.0.53}/src/internal/exception/internal_exception.py +0 -0
  21. {internal-1.0.51 → internal-1.0.53}/src/internal/ext/__init__.py +0 -0
  22. {internal-1.0.51 → internal-1.0.53}/src/internal/ext/amazon/__init__.py +0 -0
  23. {internal-1.0.51 → internal-1.0.53}/src/internal/ext/amazon/aws/__init__.py +0 -0
  24. {internal-1.0.51 → internal-1.0.53}/src/internal/ext/amazon/aws/const.py +0 -0
  25. {internal-1.0.51 → internal-1.0.53}/src/internal/http/__init__.py +0 -0
  26. {internal-1.0.51 → internal-1.0.53}/src/internal/http/responses.py +0 -0
  27. {internal-1.0.51 → internal-1.0.53}/src/internal/interface/__init__.py +0 -0
  28. {internal-1.0.51 → internal-1.0.53}/src/internal/interface/base_interface.py +0 -0
  29. {internal-1.0.51 → internal-1.0.53}/src/internal/middleware/__init__.py +0 -0
  30. {internal-1.0.51 → internal-1.0.53}/src/internal/middleware/log_request.py +0 -0
  31. {internal-1.0.51 → internal-1.0.53}/src/internal/model/__init__.py +0 -0
  32. {internal-1.0.51 → internal-1.0.53}/src/internal/model/base_model.py +0 -0
  33. {internal-1.0.51 → internal-1.0.53}/src/internal/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 1.0.51
3
+ Version: 1.0.53
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "internal"
3
- version = "1.0.51"
3
+ version = "1.0.53"
4
4
  description = ""
5
5
  authors = ["Ray <ray@cruisys.com>"]
6
6
  readme = "README.md"
@@ -16,6 +16,7 @@ from fastapi.middleware.cors import CORSMiddleware
16
16
  from . import database
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
+ from .exception.internal_exception import BadGatewayException, GatewayTimeoutException
19
20
  from .ext.amazon import aws
20
21
  from .http.requests import async_request
21
22
  from .http.responses import async_response
@@ -125,6 +126,24 @@ class BaseFactory(metaclass=ABCMeta):
125
126
  @app.exception_handler(InternalBaseException)
126
127
  async def http_exception_handler(request: Request, exc: InternalBaseException):
127
128
  detail = exc.detail
129
+
130
+ if isinstance(exc, BadGatewayException):
131
+ if self.get_app_config().WEBHOOK_BASE_URL:
132
+ message = f"【{self.DEFAULT_APP_NAME}】Bad gateway, request:{request.__dict__}, exc:{exc}"
133
+ payload = {"text": message}
134
+ try:
135
+ await async_request(app, "POST", self.get_app_config().WEBHOOK_BASE_URL, json=payload)
136
+ except Exception as e:
137
+ app.state.logger.warn(f"Notify failure, Exception:{e}")
138
+ elif isinstance(exc, GatewayTimeoutException):
139
+ if self.get_app_config().WEBHOOK_BASE_URL:
140
+ message = f"【{self.DEFAULT_APP_NAME}】Gateway timeout, request:{request.__dict__}, exc:{exc}"
141
+ payload = {"text": message}
142
+ try:
143
+ await async_request(app, "POST", self.get_app_config().WEBHOOK_BASE_URL, json=payload)
144
+ except Exception as e:
145
+ app.state.logger.warn(f"Notify failure, Exception:{e}")
146
+
128
147
  return await async_response(data=detail.get("data"), code=detail.get("code"), message=detail.get("message"),
129
148
  status_code=exc.status_code)
130
149
 
@@ -36,3 +36,12 @@ async def async_request(app: FastAPI, method, url, current_user: dict = None, **
36
36
  app.state.logger.warn(
37
37
  f"async_request(), Exception, exc: {exc}, url: {url}, method: {method}, kwargs: {kwargs}")
38
38
  raise BadGatewayException(str(exc))
39
+
40
+
41
+ async def send_webhook_message(app: FastAPI, message: str):
42
+ if app.state.config.WEBHOOK_BASE_URL:
43
+ payload = {"text": message}
44
+ try:
45
+ await async_request(app, "POST", app.state.config.WEBHOOK_BASE_URL, json=payload)
46
+ except Exception as e:
47
+ app.state.logger.warn(f"Notify failure, Exception:{e}")
@@ -1,3 +1,5 @@
1
+ import arrow
2
+ from datetime import datetime
1
3
  from typing import Optional
2
4
 
3
5
  import dictdiffer
@@ -13,11 +15,13 @@ class Operate(BaseModel):
13
15
  async def generate_operate(cls, original: dict = None, compare: dict = None):
14
16
  if original:
15
17
  original = await cls.remove_ignore_field(original)
18
+ await cls.convert_datetime_timezone_utc_field(original)
16
19
  else:
17
20
  original = {}
18
21
 
19
22
  if compare:
20
23
  compare = await cls.remove_ignore_field(compare)
24
+ await cls.convert_datetime_timezone_utc_field(compare)
21
25
  else:
22
26
  compare = {}
23
27
 
@@ -43,3 +47,10 @@ class Operate(BaseModel):
43
47
  @classmethod
44
48
  async def remove_ignore_field(cls, model_dict: dict):
45
49
  return {k: v for k, v in model_dict.items() if k not in ['create_time', 'update_time']}
50
+
51
+ @classmethod
52
+ async def convert_datetime_timezone_utc_field(cls, model_dict: dict):
53
+ # 統一使用arrow.get取代datetime,使其包含tzinfo,避免diff因時區有無判斷錯誤
54
+ for k, v in model_dict.items():
55
+ if isinstance(v, datetime):
56
+ model_dict[k] = arrow.get(v).datetime
File without changes