internal 1.1.15__tar.gz → 1.1.17__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.1.15 → internal-1.1.17}/PKG-INFO +1 -1
- {internal-1.1.15 → internal-1.1.17}/pyproject.toml +1 -1
- {internal-1.1.15 → internal-1.1.17}/src/internal/base_config.py +7 -1
- {internal-1.1.15 → internal-1.1.17}/src/internal/http/requests.py +4 -8
- {internal-1.1.15 → internal-1.1.17}/README.md +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/base_factory.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/cache_redis.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/contact_type.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/description_type.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/device_code.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/event_code.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/lpr_direction.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/notify_type.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/operator_type.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/order_type.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/common_enum/websocket_channel.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/const.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/database.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/exception/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/exception/app_exception.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/exception/base_exception.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/exception/internal_exception.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/ext/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/ext/amazon/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/ext/amazon/aws/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/ext/amazon/aws/const.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/http/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/http/responses.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/interface/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/interface/base_interface.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/middleware/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/middleware/log_request.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/model/__init__.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/model/base_model.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/model/operate.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/utils.py +0 -0
- {internal-1.1.15 → internal-1.1.17}/src/internal/validator_utils.py +0 -0
|
@@ -15,10 +15,13 @@ class BaseConfig(BaseSettings):
|
|
|
15
15
|
REQUEST_PROXY: str = ''
|
|
16
16
|
REQUEST_RETRY_COUNT: int = 2
|
|
17
17
|
REQUEST_RETRY_DELAY_INITIAL_SECONDS: float = 1.0
|
|
18
|
+
REQUEST_RETRY_DELAY_FACTOR: float = 1.5
|
|
19
|
+
REQUEST_RETRY_DELAY_RANDOM_JITTER_MIN: float = 0.0
|
|
20
|
+
REQUEST_RETRY_DELAY_RANDOM_JITTER_MAX: float = 0.5
|
|
18
21
|
REQUEST_CONN_POOL_TIMEOUT: float = 5.0
|
|
19
22
|
REQUEST_CONN_TIMEOUT: float = 5.0
|
|
20
23
|
REQUEST_WRITE_TIMEOUT: float = 5.0
|
|
21
|
-
RESPONSE_READ_TIMEOUT: float =
|
|
24
|
+
RESPONSE_READ_TIMEOUT: float = 10.0
|
|
22
25
|
|
|
23
26
|
# AWS
|
|
24
27
|
AWS_ACCESS_KEY_ID: str = ""
|
|
@@ -55,6 +58,9 @@ class BaseConfig(BaseSettings):
|
|
|
55
58
|
WEBHOOK_BASE_URL: str = ""
|
|
56
59
|
WEBHOOK_RETRY_COUNT: int = 5
|
|
57
60
|
WEBHOOK_RETRY_DELAY_INITIAL_SECONDS: float = 1.0
|
|
61
|
+
WEBHOOK_RETRY_DELAY_FACTOR: float = 2.0
|
|
62
|
+
WEBHOOK_RETRY_DELAY_RANDOM_JITTER_MIN: float = 0.0
|
|
63
|
+
WEBHOOK_RETRY_DELAY_RANDOM_JITTER_MAX: float = 0.5
|
|
58
64
|
|
|
59
65
|
# Default System Account Password
|
|
60
66
|
SYSTEM_ACCOUNT: str = "cruisys"
|
|
@@ -77,9 +77,7 @@ async def async_request(app: FastAPI, method, url, current_user: dict = None,
|
|
|
77
77
|
current_delay = request_retry_delay_initial_seconds
|
|
78
78
|
|
|
79
79
|
while retries <= request_retry_count:
|
|
80
|
-
if retries
|
|
81
|
-
app.state.logger.warn(f"【{app.title}】 \nURL: {method} {url} \nkwargs: {kwargs} \n重新嘗試送請求 (第 1 次嘗試)...")
|
|
82
|
-
else:
|
|
80
|
+
if retries > 0:
|
|
83
81
|
app.state.logger.warn(f"【{app.title}】 \nURL: {method} {url} \nkwargs: {kwargs} \n重新嘗試送請求 (第 {retries} 次嘗試)...")
|
|
84
82
|
|
|
85
83
|
try:
|
|
@@ -89,7 +87,7 @@ async def async_request(app: FastAPI, method, url, current_user: dict = None,
|
|
|
89
87
|
except GatewayTimeoutException as e:
|
|
90
88
|
if retries < request_retry_count:
|
|
91
89
|
# 計算下一次的延遲時間:current_delay * 2^retries + 隨機抖動
|
|
92
|
-
sleep_time = current_delay * (
|
|
90
|
+
sleep_time = current_delay * (app.state.config.REQUEST_RETRY_DELAY_FACTOR ** retries) + random.uniform(app.state.config.REQUEST_RETRY_DELAY_RANDOM_JITTER_MIN, app.state.config.REQUEST_RETRY_DELAY_RANDOM_JITTER_MAX)
|
|
93
91
|
app.state.logger.warn(f"【{app.title}】 \nURL: {method} {url} \nkwargs: {kwargs} \n等待 {sleep_time:.2f} 秒後重試...")
|
|
94
92
|
# 使用 asyncio.sleep 進行異步等待,不會阻塞主執行緒
|
|
95
93
|
await asyncio.sleep(sleep_time)
|
|
@@ -125,9 +123,7 @@ async def send_webhook_message(app: FastAPI, message: str):
|
|
|
125
123
|
current_delay = app.state.config.WEBHOOK_RETRY_DELAY_INITIAL_SECONDS
|
|
126
124
|
|
|
127
125
|
while retries <= retry_count:
|
|
128
|
-
if retries
|
|
129
|
-
app.state.logger.warn(f"嘗試發送訊息 (第 1 次嘗試)...")
|
|
130
|
-
else:
|
|
126
|
+
if retries > 0:
|
|
131
127
|
app.state.logger.warn(f"重新嘗試發送訊息 (第 {retries} 次嘗試)...")
|
|
132
128
|
|
|
133
129
|
try:
|
|
@@ -139,7 +135,7 @@ async def send_webhook_message(app: FastAPI, message: str):
|
|
|
139
135
|
app.state.logger.warn(f"收到 429 錯誤:{e.response.status_code} - {e.response.text}")
|
|
140
136
|
if retries < retry_count:
|
|
141
137
|
# 計算下一次的延遲時間:current_delay * 2^retries + 隨機抖動
|
|
142
|
-
sleep_time = current_delay * (
|
|
138
|
+
sleep_time = current_delay * (app.state.config.WEBHOOK_RETRY_DELAY_FACTOR ** retries) + random.uniform(app.state.config.WEBHOOK_RETRY_DELAY_RANDOM_JITTER_MIN, app.state.config.WEBHOOK_RETRY_DELAY_RANDOM_JITTER_MAX)
|
|
143
139
|
app.state.logger.warn(f"等待 {sleep_time:.2f} 秒後重試...")
|
|
144
140
|
# 使用 asyncio.sleep 進行異步等待,不會阻塞主執行緒
|
|
145
141
|
await asyncio.sleep(sleep_time)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|