sycommon-python-lib 0.1.11__tar.gz → 0.1.13__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 sycommon-python-lib might be problematic. Click here for more details.
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/PKG-INFO +1 -1
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/pyproject.toml +1 -1
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/health/health_check.py +1 -1
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/rabbitmq/rabbitmq_client.py +7 -19
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/rabbitmq/rabbitmq_service.py +2 -3
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/synacos/nacos_service.py +70 -9
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/PKG-INFO +1 -1
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/README.md +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/setup.cfg +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/command/cli.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/Config.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/DatabaseConfig.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/EmbeddingConfig.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/LLMConfig.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/MQConfig.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/RerankerConfig.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/database/base_db_service.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/database/database_service.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/health/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/health/ping.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/logging/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/logging/kafka_log.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/logging/logger_wrapper.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/context.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/cors.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/docs.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/exception.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/middleware.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/monitor_memory.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/mq.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/timeout.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/traceid.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/base_http.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/log.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqlistener_config.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqmsg_model.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqsend_config.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/sso_user.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/services.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/synacos/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/synacos/feign.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/tools/__init__.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/tools/docs.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/tools/snowflake.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/tools/timing.py +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/SOURCES.txt +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/dependency_links.txt +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/requires.txt +0 -0
- {sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon_python_lib.egg-info/top_level.txt +0 -0
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/rabbitmq/rabbitmq_client.py
RENAMED
|
@@ -47,10 +47,9 @@ class RabbitMQClient:
|
|
|
47
47
|
app_name: str = "",
|
|
48
48
|
reconnection_delay: int = 1,
|
|
49
49
|
max_reconnection_attempts: int = 5,
|
|
50
|
-
heartbeat: int =
|
|
50
|
+
heartbeat: int = 10,
|
|
51
51
|
prefetch_count: int = 2,
|
|
52
|
-
|
|
53
|
-
consumption_stall_threshold: int = 120
|
|
52
|
+
consumption_stall_threshold: int = 10
|
|
54
53
|
):
|
|
55
54
|
"""
|
|
56
55
|
初始化RabbitMQ客户端,支持集群多节点配置
|
|
@@ -75,7 +74,6 @@ class RabbitMQClient:
|
|
|
75
74
|
:param max_reconnection_attempts: 最大重连尝试次数
|
|
76
75
|
:param heartbeat: 心跳间隔(秒)
|
|
77
76
|
:param prefetch_count: 预取消息数量
|
|
78
|
-
:param message_process_timeout: 消息处理超时时间(秒)
|
|
79
77
|
:param consumption_stall_threshold: 消费停滞检测阈值(秒)
|
|
80
78
|
"""
|
|
81
79
|
# 连接参数 - 支持多主机
|
|
@@ -109,7 +107,6 @@ class RabbitMQClient:
|
|
|
109
107
|
self.heartbeat = heartbeat
|
|
110
108
|
|
|
111
109
|
# 消息处理参数
|
|
112
|
-
self.message_process_timeout = message_process_timeout
|
|
113
110
|
self.consumption_stall_threshold = consumption_stall_threshold
|
|
114
111
|
|
|
115
112
|
# 连接和通道对象
|
|
@@ -263,6 +260,7 @@ class RabbitMQClient:
|
|
|
263
260
|
password=self.password,
|
|
264
261
|
virtualhost=self.virtualhost,
|
|
265
262
|
heartbeat=self.heartbeat,
|
|
263
|
+
loop=asyncio.get_event_loop(),
|
|
266
264
|
client_properties={
|
|
267
265
|
"connection_name": f"{self.app_name}@{host}"
|
|
268
266
|
}
|
|
@@ -477,12 +475,13 @@ class RabbitMQClient:
|
|
|
477
475
|
if self._is_consuming:
|
|
478
476
|
current_time = asyncio.get_event_loop().time()
|
|
479
477
|
if current_time - self._last_message_processed > self.consumption_stall_threshold:
|
|
480
|
-
logger.warning(
|
|
481
|
-
|
|
478
|
+
# logger.warning(
|
|
479
|
+
# f"检测到消费停滞超过 {self.consumption_stall_threshold} 秒 (主机: {self._active_host}),将重启消费者")
|
|
482
480
|
if self._is_consuming and self.message_handler:
|
|
483
481
|
await self.stop_consuming()
|
|
482
|
+
await asyncio.sleep(1)
|
|
484
483
|
await self.start_consuming()
|
|
485
|
-
logger.info("消费者已重启以恢复消费")
|
|
484
|
+
# logger.info("消费者已重启以恢复消费")
|
|
486
485
|
except Exception as e:
|
|
487
486
|
logger.error(f"监控任务出错: {str(e)}")
|
|
488
487
|
await asyncio.sleep(1)
|
|
@@ -832,17 +831,6 @@ class RabbitMQClient:
|
|
|
832
831
|
# 解析消息
|
|
833
832
|
parsed_data = await self._parse_message(message)
|
|
834
833
|
|
|
835
|
-
# 消息处理超时控制
|
|
836
|
-
# try:
|
|
837
|
-
# await asyncio.wait_for(
|
|
838
|
-
# self.message_handler(MQMsgModel(**parsed_data), message),
|
|
839
|
-
# timeout=self.message_process_timeout
|
|
840
|
-
# )
|
|
841
|
-
# except asyncio.TimeoutError:
|
|
842
|
-
# logger.error(
|
|
843
|
-
# f"消息 {message_id} 处理超时(超过 {self.message_process_timeout} 秒)(主机: {self._active_host})")
|
|
844
|
-
# await message.ack() # 超时也确认,避免无限重试
|
|
845
|
-
# return
|
|
846
834
|
await self.message_handler(MQMsgModel(**parsed_data), message)
|
|
847
835
|
|
|
848
836
|
# 处理成功,确认消息
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/rabbitmq/rabbitmq_service.py
RENAMED
|
@@ -129,11 +129,10 @@ class RabbitMQService:
|
|
|
129
129
|
reconnection_delay=kwargs.get('reconnection_delay', 1),
|
|
130
130
|
max_reconnection_attempts=kwargs.get(
|
|
131
131
|
'max_reconnection_attempts', 5),
|
|
132
|
-
heartbeat=kwargs.get('heartbeat',
|
|
132
|
+
heartbeat=kwargs.get('heartbeat', 10),
|
|
133
133
|
prefetch_count=kwargs.get('prefetch_count', 2),
|
|
134
|
-
message_process_timeout=kwargs.get('message_process_timeout', 30),
|
|
135
134
|
consumption_stall_threshold=kwargs.get(
|
|
136
|
-
'consumption_stall_threshold',
|
|
135
|
+
'consumption_stall_threshold', 10)
|
|
137
136
|
)
|
|
138
137
|
|
|
139
138
|
@classmethod
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/synacos/nacos_service.py
RENAMED
|
@@ -66,6 +66,10 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
66
66
|
self.real_ip = self.get_service_ip(self.host)
|
|
67
67
|
self._long_term_retry_count = 0 # 长期重试计数器
|
|
68
68
|
|
|
69
|
+
# 轮询索引,用于在所有实例中进行轮询选择
|
|
70
|
+
self._round_robin_index = 0
|
|
71
|
+
self._round_robin_lock = threading.Lock() # 保护轮询索引的线程安全
|
|
72
|
+
|
|
69
73
|
if self.enable_register_nacos:
|
|
70
74
|
# 初始化客户端(仅在首次调用时执行)
|
|
71
75
|
self._initialize_client()
|
|
@@ -361,7 +365,12 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
361
365
|
self.registered = False
|
|
362
366
|
SYLogger.warning("nacos:本地状态显示已注册,但Nacos中未找到服务实例,准备重新注册")
|
|
363
367
|
|
|
364
|
-
metadata = {
|
|
368
|
+
metadata = {
|
|
369
|
+
"ignore-metrics": "true",
|
|
370
|
+
"preserved.heart.beat.interval": "3000", # 心跳间隔 3 秒
|
|
371
|
+
"preserved.heart.beat.timeout": "15000", # 心跳超时 15 秒
|
|
372
|
+
"preserved.ip.delete.timeout": "30000" # 实例删除超时 30 秒
|
|
373
|
+
}
|
|
365
374
|
if self.version:
|
|
366
375
|
metadata["version"] = self.version
|
|
367
376
|
|
|
@@ -506,7 +515,11 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
506
515
|
f"nacos:心跳发送失败,已持续{current_time - self._last_successful_heartbeat:.1f}秒")
|
|
507
516
|
else:
|
|
508
517
|
SYLogger.warning("nacos:服务未注册,尝试重新注册")
|
|
509
|
-
|
|
518
|
+
# 检查线程池是否已关闭
|
|
519
|
+
if not self._executor._shutdown:
|
|
520
|
+
self._executor.submit(self.register_with_retry)
|
|
521
|
+
else:
|
|
522
|
+
SYLogger.warning("nacos:线程池已关闭,无法提交注册任务")
|
|
510
523
|
finally:
|
|
511
524
|
last_heartbeat_time = time.time() # 更新上次执行时间
|
|
512
525
|
|
|
@@ -641,11 +654,11 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
641
654
|
finally:
|
|
642
655
|
self._shutdown_event.set()
|
|
643
656
|
# 优雅地关闭线程池
|
|
644
|
-
if self._executor:
|
|
657
|
+
if self._executor and not self._executor._shutdown:
|
|
645
658
|
self._executor.shutdown(wait=True)
|
|
646
|
-
if self._heartbeat_executor:
|
|
659
|
+
if self._heartbeat_executor and not self._heartbeat_executor._shutdown:
|
|
647
660
|
self._heartbeat_executor.shutdown(wait=True)
|
|
648
|
-
if self._monitor_executor:
|
|
661
|
+
if self._monitor_executor and not self._monitor_executor._shutdown:
|
|
649
662
|
self._monitor_executor.shutdown(wait=True)
|
|
650
663
|
|
|
651
664
|
def handle_signal(self, signum, frame):
|
|
@@ -731,8 +744,13 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
731
744
|
|
|
732
745
|
return self.get_service_instances(service_name, group, version)
|
|
733
746
|
|
|
734
|
-
def get_service_instances(self, service_name: str, group: str = "DEFAULT_GROUP",
|
|
735
|
-
"""
|
|
747
|
+
def get_service_instances(self, service_name: str, group: str = "DEFAULT_GROUP", target_version: str = None) -> List[Dict]:
|
|
748
|
+
"""
|
|
749
|
+
获取服务实例列表,并按照以下优先级规则筛选:
|
|
750
|
+
1. 相同版本号的实例
|
|
751
|
+
2. 无版本号的实例
|
|
752
|
+
3. 所有实例中轮询
|
|
753
|
+
"""
|
|
736
754
|
try:
|
|
737
755
|
namespace_id = self.nacos_config['namespaceId']
|
|
738
756
|
instances = self.nacos_client.list_naming_instance(
|
|
@@ -741,13 +759,56 @@ class NacosService(metaclass=SingletonMeta):
|
|
|
741
759
|
group_name=group,
|
|
742
760
|
healthy_only=True,
|
|
743
761
|
)
|
|
762
|
+
|
|
744
763
|
if not instances or 'hosts' not in instances:
|
|
764
|
+
SYLogger.info(f"nacos:未发现 {service_name} 的服务实例")
|
|
745
765
|
return []
|
|
746
766
|
|
|
767
|
+
all_instances = instances.get('hosts', [])
|
|
768
|
+
SYLogger.info(
|
|
769
|
+
f"nacos:共发现 {len(all_instances)} 个 {service_name} 服务实例")
|
|
770
|
+
|
|
771
|
+
# 确定要使用的目标版本,如果未指定则使用当前服务的版本
|
|
772
|
+
version_to_use = target_version or self.version
|
|
773
|
+
|
|
774
|
+
# 按规则筛选实例
|
|
775
|
+
if version_to_use:
|
|
776
|
+
# 1. 筛选相同版本号的实例
|
|
777
|
+
same_version_instances = [
|
|
778
|
+
instance for instance in all_instances
|
|
779
|
+
if instance.get('metadata', {}).get('version') == version_to_use
|
|
780
|
+
]
|
|
781
|
+
|
|
782
|
+
if same_version_instances:
|
|
783
|
+
SYLogger.info(
|
|
784
|
+
f"nacos:筛选出 {len(same_version_instances)} 个与当前版本({version_to_use})匹配的实例")
|
|
785
|
+
return same_version_instances
|
|
786
|
+
|
|
787
|
+
# 2. 如果没有相同版本的实例,筛选无版本号的实例
|
|
788
|
+
no_version_instances = [
|
|
789
|
+
instance for instance in all_instances
|
|
790
|
+
if 'version' not in instance.get('metadata', {})
|
|
791
|
+
]
|
|
792
|
+
|
|
793
|
+
if no_version_instances:
|
|
794
|
+
SYLogger.info(
|
|
795
|
+
f"nacos:未找到相同版本({version_to_use})的实例,筛选出 {len(no_version_instances)} 个无版本号的实例")
|
|
796
|
+
return no_version_instances
|
|
797
|
+
|
|
798
|
+
# 3. 如果没有指定版本或前两个规则都不满足,使用轮询方式选择所有健康实例
|
|
747
799
|
SYLogger.info(
|
|
748
|
-
f"nacos
|
|
800
|
+
f"nacos:使用轮询方式从 {len(all_instances)} 个实例中选择")
|
|
801
|
+
|
|
802
|
+
# 线程安全地获取下一个轮询索引
|
|
803
|
+
with self._round_robin_lock:
|
|
804
|
+
selected_index = self._round_robin_index % len(all_instances)
|
|
805
|
+
# 更新轮询索引,为下一次请求做准备
|
|
806
|
+
self._round_robin_index = (
|
|
807
|
+
selected_index + 1) % len(all_instances)
|
|
808
|
+
|
|
809
|
+
# 返回包含当前选中实例的列表
|
|
810
|
+
return [all_instances[selected_index]]
|
|
749
811
|
|
|
750
|
-
return instances.get('hosts', [])
|
|
751
812
|
except Exception as e:
|
|
752
813
|
SYLogger.error(f"nacos:服务发现失败: {service_name}: {str(e)}")
|
|
753
814
|
return []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/DatabaseConfig.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/EmbeddingConfig.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/config/RerankerConfig.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/database/base_db_service.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/database/database_service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/logging/logger_wrapper.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/exception.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/middleware.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/monitor_memory.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/timeout.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/middleware/traceid.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqlistener_config.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqmsg_model.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.11 → sycommon_python_lib-0.1.13}/src/sycommon/models/mqsend_config.py
RENAMED
|
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
|