internal 1.0.46__tar.gz → 1.0.48__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.46 → internal-1.0.48}/PKG-INFO +1 -1
  2. {internal-1.0.46 → internal-1.0.48}/pyproject.toml +1 -1
  3. {internal-1.0.46 → internal-1.0.48}/src/internal/base_factory.py +27 -10
  4. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/event_trigger_type.py +7 -1
  5. {internal-1.0.46 → internal-1.0.48}/src/internal/database.py +9 -6
  6. {internal-1.0.46 → internal-1.0.48}/README.md +0 -0
  7. {internal-1.0.46 → internal-1.0.48}/src/internal/__init__.py +0 -0
  8. {internal-1.0.46 → internal-1.0.48}/src/internal/base_config.py +0 -0
  9. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/__init__.py +0 -0
  10. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/contact_type.py +0 -0
  11. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/description_type.py +0 -0
  12. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/lpnr_direction.py +0 -0
  13. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/operator_type.py +0 -0
  14. {internal-1.0.46 → internal-1.0.48}/src/internal/common_enum/order_type.py +0 -0
  15. {internal-1.0.46 → internal-1.0.48}/src/internal/const.py +0 -0
  16. {internal-1.0.46 → internal-1.0.48}/src/internal/exception/__init__.py +0 -0
  17. {internal-1.0.46 → internal-1.0.48}/src/internal/exception/base_exception.py +0 -0
  18. {internal-1.0.46 → internal-1.0.48}/src/internal/exception/internal_exception.py +0 -0
  19. {internal-1.0.46 → internal-1.0.48}/src/internal/ext/__init__.py +0 -0
  20. {internal-1.0.46 → internal-1.0.48}/src/internal/ext/amazon/__init__.py +0 -0
  21. {internal-1.0.46 → internal-1.0.48}/src/internal/ext/amazon/aws/__init__.py +0 -0
  22. {internal-1.0.46 → internal-1.0.48}/src/internal/ext/amazon/aws/const.py +0 -0
  23. {internal-1.0.46 → internal-1.0.48}/src/internal/http/__init__.py +0 -0
  24. {internal-1.0.46 → internal-1.0.48}/src/internal/http/requests.py +0 -0
  25. {internal-1.0.46 → internal-1.0.48}/src/internal/http/responses.py +0 -0
  26. {internal-1.0.46 → internal-1.0.48}/src/internal/interface/__init__.py +0 -0
  27. {internal-1.0.46 → internal-1.0.48}/src/internal/interface/base_interface.py +0 -0
  28. {internal-1.0.46 → internal-1.0.48}/src/internal/middleware/__init__.py +0 -0
  29. {internal-1.0.46 → internal-1.0.48}/src/internal/middleware/log_request.py +0 -0
  30. {internal-1.0.46 → internal-1.0.48}/src/internal/model/__init__.py +0 -0
  31. {internal-1.0.46 → internal-1.0.48}/src/internal/model/base_model.py +0 -0
  32. {internal-1.0.46 → internal-1.0.48}/src/internal/model/operate.py +0 -0
  33. {internal-1.0.46 → internal-1.0.48}/src/internal/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 1.0.46
3
+ Version: 1.0.48
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.46"
3
+ version = "1.0.48"
4
4
  description = ""
5
5
  authors = ["Ray <ray@cruisys.com>"]
6
6
  readme = "README.md"
@@ -3,6 +3,7 @@ import logging.handlers
3
3
  import os
4
4
  import traceback
5
5
  from abc import ABCMeta, abstractmethod
6
+ from contextlib import asynccontextmanager
6
7
  from functools import lru_cache
7
8
 
8
9
  import dotenv
@@ -44,6 +45,12 @@ class BaseFactory(metaclass=ABCMeta):
44
45
  Each factory should define what model it wants.
45
46
  """
46
47
 
48
+ async def init_state_scheduler_app(self, app, app_config):
49
+ """
50
+ Each factory should define what model it wants.
51
+ """
52
+ pass
53
+
47
54
  @abstractmethod
48
55
  @lru_cache()
49
56
  def get_app_config(self):
@@ -52,15 +59,31 @@ class BaseFactory(metaclass=ABCMeta):
52
59
  """
53
60
 
54
61
  def create_app(self, title=None) -> FastAPI:
62
+
63
+ @asynccontextmanager
64
+ async def lifespan(app: FastAPI):
65
+ await mongodb.connect()
66
+ document_model_list = await self.get_document_model_list()
67
+ await init_beanie(database=app.state.db.get_database(), document_models=document_model_list)
68
+ app.state.logger.info("Database connected")
69
+ await self.init_state_cache(app, self.get_app_config())
70
+ app.state.logger.info("Initialization state cache done")
71
+ await self.init_state_scheduler_app(app, self.get_app_config())
72
+ app.state.logger.info("Initialization state scheduler app done")
73
+ yield
74
+ await mongodb.close()
75
+ app.state.logger.info("Database disconnected")
76
+
55
77
  if title is None:
56
78
  title = self.DEFAULT_APP_NAME
57
79
 
58
80
  if self.get_app_config().DEBUG:
59
81
  app = FastAPI(openapi_url=self.get_app_config().OPEN_API_URL, title=title,
60
- debug=self.get_app_config().DEBUG, version=self.API_VERSION)
82
+ debug=self.get_app_config().DEBUG, version=self.API_VERSION, lifespan=lifespan)
61
83
  else:
62
84
  app = FastAPI(openapi_url=self.get_app_config().OPEN_API_URL, title=title,
63
- debug=self.get_app_config().DEBUG, version=self.API_VERSION, docs_url=None, redoc_url=None)
85
+ debug=self.get_app_config().DEBUG, version=self.API_VERSION, lifespan=lifespan, docs_url=None,
86
+ redoc_url=None)
64
87
 
65
88
  origins = ["*"]
66
89
 
@@ -92,17 +115,11 @@ class BaseFactory(metaclass=ABCMeta):
92
115
 
93
116
  @app.on_event("startup")
94
117
  async def startup_db_client():
95
- await mongodb.connect()
96
- document_model_list = await self.get_document_model_list()
97
- await init_beanie(database=app.state.db.get_database(), document_models=document_model_list)
98
- app.state.logger.info("Database connected")
99
- await self.init_state_cache(app, self.get_app_config())
100
- app.state.logger.info("Initialization state cache done")
118
+ print("startup_db_client================run")
101
119
 
102
120
  @app.on_event("shutdown")
103
121
  async def shutdown_db_client():
104
- await mongodb.close()
105
- app.state.logger.info("Database disconnected")
122
+ print("shutdown_db_client============run")
106
123
 
107
124
  app.state.db = mongodb
108
125
  app.state.config = self.get_app_config()
@@ -7,6 +7,7 @@ class EventTriggerTypeEnum(str, Enum):
7
7
  MANUAL_TRACING_STOP_SERVICE_TICKET = "manual_tracking_stop_service_ticket"
8
8
  MANUAL_CREATE_SERVICE_TICKET = "manual_create_service_ticket"
9
9
  MANUAL_IMPORT_RESERVATION_SMWS = "manual_import_reservation_smws"
10
+ MANUAL_MODIFY_USER_SERVICE_TICKET = "manual_modify_user_service_ticket"
10
11
  MANUAL_MODIFY_ESTIMATED_ARRIVAL_TIME_SERVICE_TICKET = "manual_modify_estimated_arrival_time_service_ticket"
11
12
  MANUAL_MODIFY_ESTIMATED_DELIVERY_TIME_SERVICE_TICKET = "manual_modify_estimated_delivery_time_service_ticket"
12
13
  MANUAL_BOOKING_MESSAGE_SERVICE_TICKET = "manual_booking_message_service_ticket"
@@ -15,5 +16,10 @@ class EventTriggerTypeEnum(str, Enum):
15
16
  NOSHOW_SERVICE_TICKET_AUTO_CANCEL = "noshow_service_ticket_auto_cancel"
16
17
  IMPORT_RESERVATION_CONFLICT_AUTO_CANCEL = "import_reservation_conflict_auto_cancel"
17
18
  BOOKING_REMINDING_SERVICE_TICKET = "booking_reminding_service_ticket"
18
- LPNR_IN = "lpnr_in"
19
+
20
+ LPNR_IN_ESTABLISHED = "lpnr_in_established"
21
+ LPNR_IN_RECEPTION = "lpnr_in_reception"
22
+ LPNR_IN_WORKING = "lpnr_in_working"
19
23
  LPNR_OUT = "lpnr_out"
24
+ LPNR_OUT_GENERAL = "lpnr_out_general"
25
+ LPNR_OUT_NO_SERVE = "lpnr_out_no_serve"
@@ -5,12 +5,6 @@ from .exception.internal_exception import DatabaseInitializeFailureException, Da
5
5
 
6
6
 
7
7
  class MongoDB:
8
- # def __init__(self, connection_url: str, db_name: str, ssl: bool = False, ssl_ca_certs: str = None):
9
- # self.client = None
10
- # self.connection_url = connection_url
11
- # self.db_name = db_name
12
- # self.ssl = ssl
13
- # self.ssl_ca_certs = ssl_ca_certs
14
8
  def __init__(self, user_name: str, password: str, host: str, port: int, db_name: str, server_selection_timeout: int,
15
9
  connection_timeout: int, auth_source: str, ssl: bool = False, ssl_ca_certs: str = None):
16
10
  self.client = None
@@ -49,3 +43,12 @@ class MongoDB:
49
43
  if not self.client:
50
44
  raise DatabaseConnectFailureException()
51
45
  return self.client[self.db_name]
46
+
47
+ def get_mongodb_uri(self) -> str:
48
+ uri = f"mongodb://{self.user_name}:{self.password}@{self.host}:{self.port}/{self.db_name}?authSource={self.auth_source}&connectTimeoutMS={self.connection_timeout}&serverSelectionTimeoutMS={self.server_selection_timeout}&retryWrites=false"
49
+ if self.ssl:
50
+ uri += "&ssl=true"
51
+ if self.ssl_ca_certs and self.ssl_ca_certs != "":
52
+ uri += f"&tlsCAFile={self.ssl_ca_certs}"
53
+
54
+ return uri
File without changes