internal 1.0.52__py3-none-any.whl → 1.0.54__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_factory.py CHANGED
@@ -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
 
internal/http/requests.py CHANGED
@@ -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}")
internal/utils.py CHANGED
@@ -47,4 +47,4 @@ def update_dict_with_cast(curr_settings: BaseConfig, new_conf: dict):
47
47
 
48
48
 
49
49
  def sanitize_plate_no(plate_no):
50
- return plate_no.replace(STR_DASH, STR_EMPTY)
50
+ return plate_no.replace(STR_DASH, STR_EMPTY).upper()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 1.0.52
3
+ Version: 1.0.54
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,6 +1,6 @@
1
1
  internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  internal/base_config.py,sha256=ZdqvHlPsF6ozELgmV0ZiSpYehSscasIclLp8eAjVE24,1870
3
- internal/base_factory.py,sha256=0MQNsJrGwYIdibkg1iqptxA7hyYc-S2Pj4IjGuIA2rM,8962
3
+ internal/base_factory.py,sha256=7UUiolLWYSodc9PxqLHaZ6KqDYUU3kC4g07iVggSymU,10125
4
4
  internal/common_enum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  internal/common_enum/contact_type.py,sha256=7QkTQ71UxpaT1YHI40FpjmLz3r-UbRU-sd0m5ajH1as,142
6
6
  internal/common_enum/description_type.py,sha256=kGwkFQh6dMnjDl6ipWYpA-qbNRrhEpnPq3NleTsNwwk,118
@@ -18,7 +18,7 @@ internal/ext/amazon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
18
18
  internal/ext/amazon/aws/__init__.py,sha256=2YFjb-rHG1JaZGZiZffYDesgTAJjDshOqQbswOYzhP8,834
19
19
  internal/ext/amazon/aws/const.py,sha256=l4WMg5bKWujwOKABBkCO2zclNg3abnYOfbhD7DG8GsA,109
20
20
  internal/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- internal/http/requests.py,sha256=4Mdu_HIGDEgpgey8IPusqBn9s-3-oYGU0S49NK-khc4,1821
21
+ internal/http/requests.py,sha256=PA3Z9Yqb-TWO-bP1xVvRAw8LptZTJPPt1MrfukpVJqk,2167
22
22
  internal/http/responses.py,sha256=_xhp52Y4T8tGQ4g6U8gh71WADLECibOAV42jKSvtvtw,2923
23
23
  internal/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  internal/interface/base_interface.py,sha256=3YaVjIgLi_pZpLk5SEIk8WVkuICM8qPavT8rB0MdB5U,1536
@@ -27,7 +27,7 @@ internal/middleware/log_request.py,sha256=bXAxmvvsYDhObXzfUw4ZNreKAWOo8ee_vpb6Xi
27
27
  internal/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  internal/model/base_model.py,sha256=NS_GZvw_IqU1aZPHPpyQs6A741O34ybmzVzBPm9nGWU,3014
29
29
  internal/model/operate.py,sha256=kufXKxDknAneXTL_ycb7THBVvOmXFftYLx18bvdSARI,2004
30
- internal/utils.py,sha256=0SubS0iUhDvjSX1F4TykasA5-enYJzt2VH-f7_0BnjI,1509
31
- internal-1.0.52.dist-info/METADATA,sha256=r1OKZvB56EeglRAYrVBNli3oFvDjUdjvpLu-fz6M9a0,625
32
- internal-1.0.52.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
33
- internal-1.0.52.dist-info/RECORD,,
30
+ internal/utils.py,sha256=CXYZs4rDDe33Zac27YeknBE4uQN437ys1YAbW3Xeyow,1517
31
+ internal-1.0.54.dist-info/METADATA,sha256=1YOM__--XKLWZjha41CDJlsfh_VhFgMjBZPShqmDLG0,625
32
+ internal-1.0.54.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
33
+ internal-1.0.54.dist-info/RECORD,,