sycommon-python-lib 0.1.17__py3-none-any.whl → 0.1.19__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 sycommon-python-lib might be problematic. Click here for more details.

@@ -0,0 +1,13 @@
1
+ from fastapi import FastAPI, APIRouter
2
+
3
+
4
+ def setup_metrics_handler(app: FastAPI):
5
+ metrics_router = APIRouter()
6
+
7
+ @metrics_router.get("/metrics")
8
+ async def metrics():
9
+ return {"status": "alive"}
10
+
11
+ app.include_router(metrics_router)
12
+
13
+ return app
@@ -1,3 +1,4 @@
1
+ from src.sycommon.health.metrics import setup_metrics_handler
1
2
  from sycommon.health.ping import setup_ping_handler
2
3
  from sycommon.middleware.cors import setup_cors_handler
3
4
  from sycommon.middleware.docs import setup_docs_handler
@@ -34,6 +35,9 @@ class Middleware:
34
35
  # ping
35
36
  app = setup_ping_handler(app)
36
37
 
38
+ # metrics
39
+ app = setup_metrics_handler(app)
40
+
37
41
  # 添加mq中间件
38
42
  # app = setup_mq_middleware(app)
39
43
 
@@ -324,7 +324,11 @@ class RabbitMQClient:
324
324
  if self._is_consuming:
325
325
  current_time = asyncio.get_event_loop().time()
326
326
  if current_time - self._last_message_processed > self.consumption_stall_threshold:
327
- if self._is_consuming and self.message_handler:
327
+ if self._processing_message_ids:
328
+ logger.warning(
329
+ f"消费停滞,但有 {len(self._processing_message_ids)} 个消息正在处理,暂不重启")
330
+ else:
331
+ # 确实无消息处理,再重启
328
332
  await self.stop_consuming()
329
333
  await asyncio.sleep(1)
330
334
  await self.start_consuming()
@@ -332,7 +336,7 @@ class RabbitMQClient:
332
336
  logger.error(f"监控任务出错: {str(e)}")
333
337
  await asyncio.sleep(1)
334
338
 
335
- await asyncio.sleep(5) # 每5秒检查一次
339
+ await asyncio.sleep(30)
336
340
 
337
341
  self._monitor_task = asyncio.create_task(monitor())
338
342
 
sycommon/services.py CHANGED
@@ -1,9 +1,11 @@
1
- from typing import Any, Callable, Dict, List, Tuple, Union, Optional, AsyncGenerator
2
1
  import asyncio
3
2
  import logging
3
+ import yaml
4
4
  from contextlib import asynccontextmanager
5
+ from dotenv import load_dotenv
5
6
  from fastapi import FastAPI, applications
6
7
  from pydantic import BaseModel
8
+ from typing import Any, Callable, Dict, List, Tuple, Union, Optional, AsyncGenerator
7
9
  from sycommon.config.Config import SingletonMeta
8
10
  from sycommon.models.mqlistener_config import RabbitMQListenerConfig
9
11
  from sycommon.models.mqsend_config import RabbitMQSendConfig
@@ -41,7 +43,7 @@ class Services(metaclass=SingletonMeta):
41
43
  def plugins(
42
44
  cls,
43
45
  app: FastAPI,
44
- config: dict,
46
+ config: Optional[dict] = None,
45
47
  middleware: Optional[Callable[[FastAPI, dict], None]] = None,
46
48
  nacos_service: Optional[Callable[[dict], None]] = None,
47
49
  logging_service: Optional[Callable[[dict], None]] = None,
@@ -52,6 +54,7 @@ class Services(metaclass=SingletonMeta):
52
54
  rabbitmq_listeners: Optional[List[RabbitMQListenerConfig]] = None,
53
55
  rabbitmq_senders: Optional[List[RabbitMQSendConfig]] = None
54
56
  ) -> FastAPI:
57
+ load_dotenv()
55
58
  # 保存应用实例和配置
56
59
  cls._app = app
57
60
  cls._config = config
@@ -59,6 +62,12 @@ class Services(metaclass=SingletonMeta):
59
62
  # 设置文档
60
63
  applications.get_swagger_ui_html = custom_swagger_ui_html
61
64
  applications.get_redoc_html = custom_redoc_html
65
+ # 设置app.state host, port
66
+ if not cls._config:
67
+ config = yaml.safe_load(open('app.yaml', 'r', encoding='utf-8'))
68
+ cls._config = config
69
+ app.host = cls._config.get('Host')
70
+ app.post = cls._config.get('Port')
62
71
 
63
72
  # 立即配置非异步服务(在应用启动前)
64
73
  if middleware:
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sycommon-python-lib
3
- Version: 0.1.17
3
+ Version: 0.1.19
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
7
7
  Requires-Dist: aio-pika>=9.5.7
8
8
  Requires-Dist: aiohttp>=3.12.15
9
9
  Requires-Dist: decorator>=5.2.1
10
- Requires-Dist: fastapi>=0.117.1
10
+ Requires-Dist: fastapi>=0.118.0
11
11
  Requires-Dist: kafka-python>=2.2.15
12
12
  Requires-Dist: loguru>=0.7.3
13
13
  Requires-Dist: mysql-connector-python>=9.4.0
@@ -1,6 +1,6 @@
1
1
  command/cli.py,sha256=bP2LCLkRvfETIwWkVD70q5xFxMI4D3BpH09Ws1f-ENc,5849
2
2
  sycommon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- sycommon/services.py,sha256=jQBzJvepaUyDVxLOC39OJokgQfwME0eRj9uN-13ZPjg,8423
3
+ sycommon/services.py,sha256=s9xbXiwehZeO4ZnS_8UKFY-LBkdGwbmsK-BB3pmFZuo,8766
4
4
  sycommon/config/Config.py,sha256=9yO5b8WfvEDvkyrGrlwrLFasgh_-MjcEvGF20Gz5Xo4,3041
5
5
  sycommon/config/DatabaseConfig.py,sha256=ILiUuYT9_xJZE2W-RYuC3JCt_YLKc1sbH13-MHIOPhg,804
6
6
  sycommon/config/EmbeddingConfig.py,sha256=gPKwiDYbeu1GpdIZXMmgqM7JqBIzCXi0yYuGRLZooMI,362
@@ -12,6 +12,7 @@ sycommon/database/base_db_service.py,sha256=J5ELHMNeGfzA6zVcASPSPZ0XNKrRY3_gdGmV
12
12
  sycommon/database/database_service.py,sha256=B9tCaMsKGK87XF20YQh-eGupa3dq0JXymKnAAJvS2DQ,3060
13
13
  sycommon/health/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  sycommon/health/health_check.py,sha256=EhfbhspRpQiKJaxdtE-PzpKQO_ucaFKtQxIm16F5Mpk,391
15
+ sycommon/health/metrics.py,sha256=fHqO73JuhoZkNPR-xIlxieXiTCvttq-kG-tvxag1s1s,268
15
16
  sycommon/health/ping.py,sha256=FTlnIKk5y1mPfS1ZGOeT5IM_2udF5aqVLubEtuBp18M,250
16
17
  sycommon/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
18
  sycommon/logging/kafka_log.py,sha256=g6X46GlqJMzMMZEhbNa-eTswzkF8ILBHDYQFbjz6j54,20757
@@ -21,7 +22,7 @@ sycommon/middleware/context.py,sha256=_5ghpv4u_yAvjkgM-XDx8OnO-YI1XtntHrXsHJHZkw
21
22
  sycommon/middleware/cors.py,sha256=0B5d_ovD56wcH9TfktRs88Q09R9f8Xx5h5ALWYvE8Iw,600
22
23
  sycommon/middleware/docs.py,sha256=bVdDBIHXGVBv562MQLSroa1DgHoObxR9gFzv71PIejg,1187
23
24
  sycommon/middleware/exception.py,sha256=Bk8IchNND1wg6tUX9hf4xWeEJhvA-E_zE9ysBpRZrqE,3010
24
- sycommon/middleware/middleware.py,sha256=5jXhCatm3nS6BpRtGBNOHu59feTwikLGC2caF9AyfpY,1329
25
+ sycommon/middleware/middleware.py,sha256=6JCZQY8r5H50_-yN0gRf-MFGSC0NmCqKa6YkrbDvo0k,1451
25
26
  sycommon/middleware/monitor_memory.py,sha256=pYRK-wRuDd6enSg9Pf8tQxPdYQS6S0AyjyXeKFRLKEs,628
26
27
  sycommon/middleware/mq.py,sha256=4wBqiT5wJGcrfjk2GSr0_U3TStBxoNpHTzcRxVlMEHE,183
27
28
  sycommon/middleware/timeout.py,sha256=fImlAPLm4Oa8N9goXtT_0os1GZPCi9F92OgXU81DgDU,656
@@ -33,7 +34,7 @@ sycommon/models/mqlistener_config.py,sha256=PPwhAVJ2AWvVAvNox_1t0fuBKTyRH3Ui9cuu
33
34
  sycommon/models/mqmsg_model.py,sha256=cxn0M5b0utQK6crMYmL-1waeGYHvK3AlGaRy23clqTE,277
34
35
  sycommon/models/mqsend_config.py,sha256=NQX9dc8PpuquMG36GCVhJe8omAW1KVXXqr6lSRU6D7I,268
35
36
  sycommon/models/sso_user.py,sha256=i1WAN6k5sPcPApQEdtjpWDy7VrzWLpOrOQewGLGoGIw,2702
36
- sycommon/rabbitmq/rabbitmq_client.py,sha256=1mnccWeqBHHTPy__8kGEBX77UtAPL3_ffVoAZbbyPf4,26429
37
+ sycommon/rabbitmq/rabbitmq_client.py,sha256=XWAzQ2A6AxTwISin2biqAzbGnN6XA9T25UX0iXdxb9s,26677
37
38
  sycommon/rabbitmq/rabbitmq_pool.py,sha256=_NMOO4CZy-I_anMqpzfYinz-8373_rg5FM9eqzdjGyU,3598
38
39
  sycommon/rabbitmq/rabbitmq_service.py,sha256=lpYSavAwl-UOmz5gTgS3yj2ulfF-s7boL3lsMibN-JM,28881
39
40
  sycommon/sse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -46,8 +47,8 @@ sycommon/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
47
  sycommon/tools/docs.py,sha256=OPj2ETheuWjXLyaXtaZPbwmJKfJaYXV5s4XMVAUNrms,1607
47
48
  sycommon/tools/snowflake.py,sha256=rc-VUjBMMpdAvbnHroVwfVt1xzApJbTCthUy9mglAuw,237
48
49
  sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
49
- sycommon_python_lib-0.1.17.dist-info/METADATA,sha256=Yz-MTXIYKGwCFWX3SRSsNQpSiPXZ3vAhsSLig9fl890,7005
50
- sycommon_python_lib-0.1.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
- sycommon_python_lib-0.1.17.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
52
- sycommon_python_lib-0.1.17.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
53
- sycommon_python_lib-0.1.17.dist-info/RECORD,,
50
+ sycommon_python_lib-0.1.19.dist-info/METADATA,sha256=F6EDuoMcntemIbJO_5BNxUs8BMq6jeLJwtJ2t9XfnR4,7005
51
+ sycommon_python_lib-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
+ sycommon_python_lib-0.1.19.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
53
+ sycommon_python_lib-0.1.19.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
54
+ sycommon_python_lib-0.1.19.dist-info/RECORD,,