sycommon-python-lib 0.1.24__tar.gz → 0.1.36__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.24 → sycommon_python_lib-0.1.36}/PKG-INFO +9 -9
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/pyproject.toml +9 -9
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/database/database_service.py +6 -1
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/logging/kafka_log.py +17 -7
- sycommon_python_lib-0.1.36/src/sycommon/logging/sql_logger.py +53 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/mqlistener_config.py +1 -0
- sycommon_python_lib-0.1.36/src/sycommon/rabbitmq/rabbitmq_client.py +980 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/rabbitmq/rabbitmq_service.py +231 -130
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/services.py +64 -22
- sycommon_python_lib-0.1.36/src/sycommon/synacos/example.py +153 -0
- sycommon_python_lib-0.1.36/src/sycommon/synacos/example2.py +129 -0
- sycommon_python_lib-0.1.36/src/sycommon/synacos/feign.py +178 -0
- sycommon_python_lib-0.1.36/src/sycommon/synacos/feign_client.py +317 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/synacos/nacos_service.py +14 -9
- sycommon_python_lib-0.1.36/src/sycommon/synacos/param.py +75 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon_python_lib.egg-info/PKG-INFO +9 -9
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon_python_lib.egg-info/SOURCES.txt +5 -0
- sycommon_python_lib-0.1.36/src/sycommon_python_lib.egg-info/requires.txt +15 -0
- sycommon_python_lib-0.1.24/src/sycommon/rabbitmq/rabbitmq_client.py +0 -679
- sycommon_python_lib-0.1.24/src/sycommon/synacos/feign.py +0 -513
- sycommon_python_lib-0.1.24/src/sycommon_python_lib.egg-info/requires.txt +0 -15
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/README.md +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/setup.cfg +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/command/cli.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/Config.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/DatabaseConfig.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/EmbeddingConfig.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/LLMConfig.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/MQConfig.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/RerankerConfig.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/config/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/database/base_db_service.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/health/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/health/health_check.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/health/metrics.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/health/ping.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/logging/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/logging/logger_wrapper.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/context.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/cors.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/docs.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/exception.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/middleware.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/monitor_memory.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/mq.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/timeout.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/middleware/traceid.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/base_http.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/log.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/mqmsg_model.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/mqsend_config.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/sso_user.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/rabbitmq/rabbitmq_pool.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/sse/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/sse/event.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/sse/sse.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/synacos/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/tools/__init__.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/tools/docs.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/tools/snowflake.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/tools/timing.py +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon_python_lib.egg-info/dependency_links.txt +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon_python_lib.egg-info/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon_python_lib.egg-info/top_level.txt +0 -0
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sycommon-python-lib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.36
|
|
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
|
-
Requires-Dist: aiohttp>=3.
|
|
8
|
+
Requires-Dist: aiohttp>=3.13.1
|
|
9
9
|
Requires-Dist: decorator>=5.2.1
|
|
10
|
-
Requires-Dist: fastapi>=0.
|
|
10
|
+
Requires-Dist: fastapi>=0.120.0
|
|
11
11
|
Requires-Dist: kafka-python>=2.2.15
|
|
12
12
|
Requires-Dist: loguru>=0.7.3
|
|
13
|
-
Requires-Dist: mysql-connector-python>=9.
|
|
13
|
+
Requires-Dist: mysql-connector-python>=9.5.0
|
|
14
14
|
Requires-Dist: nacos-sdk-python>=2.0.9
|
|
15
|
-
Requires-Dist: pydantic>=2.
|
|
16
|
-
Requires-Dist: python-dotenv>=1.
|
|
15
|
+
Requires-Dist: pydantic>=2.12.3
|
|
16
|
+
Requires-Dist: python-dotenv>=1.2.1
|
|
17
17
|
Requires-Dist: pyyaml>=6.0.3
|
|
18
|
-
Requires-Dist: sqlalchemy>=2.0.
|
|
19
|
-
Requires-Dist: starlette>=0.
|
|
18
|
+
Requires-Dist: sqlalchemy>=2.0.44
|
|
19
|
+
Requires-Dist: starlette>=0.48.0
|
|
20
20
|
Requires-Dist: uuid>=1.30
|
|
21
|
-
Requires-Dist: uvicorn>=0.
|
|
21
|
+
Requires-Dist: uvicorn>=0.38.0
|
|
22
22
|
|
|
23
23
|
# sycommon-python-lib
|
|
24
24
|
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sycommon-python-lib"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.36"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
dependencies = [
|
|
8
8
|
"aio-pika>=9.5.7",
|
|
9
|
-
"aiohttp>=3.
|
|
9
|
+
"aiohttp>=3.13.1",
|
|
10
10
|
"decorator>=5.2.1",
|
|
11
|
-
"fastapi>=0.
|
|
11
|
+
"fastapi>=0.120.0",
|
|
12
12
|
"kafka-python>=2.2.15",
|
|
13
13
|
"loguru>=0.7.3",
|
|
14
|
-
"mysql-connector-python>=9.
|
|
14
|
+
"mysql-connector-python>=9.5.0",
|
|
15
15
|
"nacos-sdk-python>=2.0.9",
|
|
16
|
-
"pydantic>=2.
|
|
17
|
-
"python-dotenv>=1.
|
|
16
|
+
"pydantic>=2.12.3",
|
|
17
|
+
"python-dotenv>=1.2.1",
|
|
18
18
|
"pyyaml>=6.0.3",
|
|
19
|
-
"sqlalchemy>=2.0.
|
|
20
|
-
"starlette>=0.
|
|
19
|
+
"sqlalchemy>=2.0.44",
|
|
20
|
+
"starlette>=0.48.0",
|
|
21
21
|
"uuid>=1.30",
|
|
22
|
-
"uvicorn>=0.
|
|
22
|
+
"uvicorn>=0.38.0",
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
[tool.setuptools]
|
{sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/database/database_service.py
RENAMED
|
@@ -3,6 +3,7 @@ from sqlalchemy import create_engine, text
|
|
|
3
3
|
from sycommon.config.Config import SingletonMeta
|
|
4
4
|
from sycommon.config.DatabaseConfig import DatabaseConfig, convert_dict_keys
|
|
5
5
|
from sycommon.logging.kafka_log import SYLogger
|
|
6
|
+
from sycommon.logging.sql_logger import SQLTraceLogger
|
|
6
7
|
from sycommon.synacos.nacos_service import NacosService
|
|
7
8
|
|
|
8
9
|
|
|
@@ -62,9 +63,13 @@ class DatabaseConnector(metaclass=SingletonMeta):
|
|
|
62
63
|
max_overflow=20, # 最大溢出连接数
|
|
63
64
|
pool_timeout=30, # 连接超时时间(秒)
|
|
64
65
|
pool_recycle=3600, # 连接回收时间(秒)
|
|
65
|
-
pool_pre_ping=True # 每次获取连接前检查连接是否有效
|
|
66
|
+
pool_pre_ping=True, # 每次获取连接前检查连接是否有效
|
|
67
|
+
echo=False, # 打印 SQL 语句
|
|
66
68
|
)
|
|
67
69
|
|
|
70
|
+
# 注册 SQL 日志拦截器
|
|
71
|
+
SQLTraceLogger.setup_sql_logging(self.engine)
|
|
72
|
+
|
|
68
73
|
# 测试
|
|
69
74
|
if not self.test_connection():
|
|
70
75
|
raise Exception("Database connection test failed")
|
|
@@ -173,7 +173,7 @@ class KafkaLogger(metaclass=SingletonMeta):
|
|
|
173
173
|
"className": "",
|
|
174
174
|
"sqlCost": 0,
|
|
175
175
|
"size": len(str(message)),
|
|
176
|
-
"uid": int(
|
|
176
|
+
"uid": int(Snowflake.next_id()) # 独立新的id
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
# 智能队列管理
|
|
@@ -470,12 +470,22 @@ class SYLogger:
|
|
|
470
470
|
thread_info = SYLogger._get_execution_context()
|
|
471
471
|
|
|
472
472
|
# 构建日志结构,添加线程/协程信息到threadName字段
|
|
473
|
-
request_log = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
473
|
+
request_log = {}
|
|
474
|
+
if level == "ERROR":
|
|
475
|
+
request_log = {
|
|
476
|
+
"trace_id": str(trace_id) if trace_id else Snowflake.next_id(),
|
|
477
|
+
"message": msg_str,
|
|
478
|
+
"traceback": traceback.format_exc(),
|
|
479
|
+
"level": level,
|
|
480
|
+
"threadName": thread_info
|
|
481
|
+
}
|
|
482
|
+
else:
|
|
483
|
+
request_log = {
|
|
484
|
+
"trace_id": str(trace_id) if trace_id else Snowflake.next_id(),
|
|
485
|
+
"message": msg_str,
|
|
486
|
+
"level": level,
|
|
487
|
+
"threadName": thread_info
|
|
488
|
+
}
|
|
479
489
|
|
|
480
490
|
# 选择日志级别
|
|
481
491
|
_log = ''
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from sqlalchemy import event
|
|
2
|
+
from sqlalchemy.engine import Engine
|
|
3
|
+
from sycommon.logging.kafka_log import SYLogger
|
|
4
|
+
import time
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from decimal import Decimal
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SQLTraceLogger:
|
|
10
|
+
@staticmethod
|
|
11
|
+
def setup_sql_logging(engine: Engine):
|
|
12
|
+
"""为 SQLAlchemy 引擎注册事件监听器"""
|
|
13
|
+
def serialize_params(params):
|
|
14
|
+
"""处理特殊类型参数的序列化"""
|
|
15
|
+
if isinstance(params, (list, tuple)):
|
|
16
|
+
return [serialize_params(p) for p in params]
|
|
17
|
+
elif isinstance(params, dict):
|
|
18
|
+
return {k: serialize_params(v) for k, v in params.items()}
|
|
19
|
+
elif isinstance(params, datetime):
|
|
20
|
+
return params.isoformat()
|
|
21
|
+
elif isinstance(params, Decimal):
|
|
22
|
+
return float(params)
|
|
23
|
+
else:
|
|
24
|
+
return params
|
|
25
|
+
|
|
26
|
+
@event.listens_for(Engine, "after_cursor_execute")
|
|
27
|
+
def after_cursor_execute(
|
|
28
|
+
conn, cursor, statement, parameters, context, executemany
|
|
29
|
+
):
|
|
30
|
+
try:
|
|
31
|
+
start_time = conn._execution_options.get(
|
|
32
|
+
"_start_time", time.time())
|
|
33
|
+
execution_time = (time.time() - start_time) * 1000
|
|
34
|
+
|
|
35
|
+
sql_log = {
|
|
36
|
+
"type": "SQL",
|
|
37
|
+
"statement": statement,
|
|
38
|
+
"parameters": serialize_params(parameters),
|
|
39
|
+
"execution_time_ms": round(execution_time, 2),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
SYLogger.info(f"SQL执行: {sql_log}")
|
|
43
|
+
except Exception as e:
|
|
44
|
+
SYLogger.error(f"SQL日志处理失败: {str(e)}")
|
|
45
|
+
|
|
46
|
+
@event.listens_for(Engine, "before_cursor_execute")
|
|
47
|
+
def before_cursor_execute(
|
|
48
|
+
conn, cursor, statement, parameters, context, executemany
|
|
49
|
+
):
|
|
50
|
+
try:
|
|
51
|
+
conn = conn.execution_options(_start_time=time.time())
|
|
52
|
+
except Exception as e:
|
|
53
|
+
SYLogger.error(f"SQL开始时间记录失败: {str(e)}")
|
{sycommon_python_lib-0.1.24 → sycommon_python_lib-0.1.36}/src/sycommon/models/mqlistener_config.py
RENAMED
|
@@ -31,6 +31,7 @@ class RabbitMQListenerConfig(BaseModel):
|
|
|
31
31
|
durable: bool = Field(True, description="是否持久化")
|
|
32
32
|
auto_delete: bool = Field(False, description="是否自动删除队列")
|
|
33
33
|
auto_parse_json: bool = Field(True, description="是否自动解析JSON消息")
|
|
34
|
+
prefetch_count: int = Field(2, description="mq同时消费数量")
|
|
34
35
|
|
|
35
36
|
class Config:
|
|
36
37
|
"""模型配置"""
|