sycommon-python-lib 0.1.17__py3-none-any.whl → 0.1.18__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.

@@ -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.18
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
@@ -33,7 +33,7 @@ sycommon/models/mqlistener_config.py,sha256=PPwhAVJ2AWvVAvNox_1t0fuBKTyRH3Ui9cuu
33
33
  sycommon/models/mqmsg_model.py,sha256=cxn0M5b0utQK6crMYmL-1waeGYHvK3AlGaRy23clqTE,277
34
34
  sycommon/models/mqsend_config.py,sha256=NQX9dc8PpuquMG36GCVhJe8omAW1KVXXqr6lSRU6D7I,268
35
35
  sycommon/models/sso_user.py,sha256=i1WAN6k5sPcPApQEdtjpWDy7VrzWLpOrOQewGLGoGIw,2702
36
- sycommon/rabbitmq/rabbitmq_client.py,sha256=1mnccWeqBHHTPy__8kGEBX77UtAPL3_ffVoAZbbyPf4,26429
36
+ sycommon/rabbitmq/rabbitmq_client.py,sha256=XWAzQ2A6AxTwISin2biqAzbGnN6XA9T25UX0iXdxb9s,26677
37
37
  sycommon/rabbitmq/rabbitmq_pool.py,sha256=_NMOO4CZy-I_anMqpzfYinz-8373_rg5FM9eqzdjGyU,3598
38
38
  sycommon/rabbitmq/rabbitmq_service.py,sha256=lpYSavAwl-UOmz5gTgS3yj2ulfF-s7boL3lsMibN-JM,28881
39
39
  sycommon/sse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -46,8 +46,8 @@ sycommon/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
46
  sycommon/tools/docs.py,sha256=OPj2ETheuWjXLyaXtaZPbwmJKfJaYXV5s4XMVAUNrms,1607
47
47
  sycommon/tools/snowflake.py,sha256=rc-VUjBMMpdAvbnHroVwfVt1xzApJbTCthUy9mglAuw,237
48
48
  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,,
49
+ sycommon_python_lib-0.1.18.dist-info/METADATA,sha256=PISpvnH650qHYSgDyDSsmTgS3hlCDZ2YN0j9fGBlheU,7005
50
+ sycommon_python_lib-0.1.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
+ sycommon_python_lib-0.1.18.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
52
+ sycommon_python_lib-0.1.18.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
53
+ sycommon_python_lib-0.1.18.dist-info/RECORD,,