Showing
2 changed files
with
10 additions
and
17 deletions
| @@ -6,18 +6,15 @@ import os | @@ -6,18 +6,15 @@ import os | ||
| 6 | import sys | 6 | import sys |
| 7 | import subprocess | 7 | import subprocess |
| 8 | import time | 8 | import time |
| 9 | -import json | ||
| 10 | import threading | 9 | import threading |
| 11 | from datetime import datetime | 10 | from datetime import datetime |
| 12 | -from queue import Queue, Empty | 11 | +from queue import Queue |
| 13 | from flask import Flask, render_template, request, jsonify, Response | 12 | from flask import Flask, render_template, request, jsonify, Response |
| 14 | from flask_socketio import SocketIO, emit | 13 | from flask_socketio import SocketIO, emit |
| 15 | -import signal | ||
| 16 | import atexit | 14 | import atexit |
| 17 | import requests | 15 | import requests |
| 18 | from loguru import logger | 16 | from loguru import logger |
| 19 | import importlib | 17 | import importlib |
| 20 | -import re | ||
| 21 | from pathlib import Path | 18 | from pathlib import Path |
| 22 | 19 | ||
| 23 | # 导入ReportEngine | 20 | # 导入ReportEngine |
| @@ -240,7 +237,7 @@ def initialize_system_components(): | @@ -240,7 +237,7 @@ def initialize_system_components(): | ||
| 240 | except Exception as exc: # pragma: no cover - 安全捕获 | 237 | except Exception as exc: # pragma: no cover - 安全捕获 |
| 241 | message = f"停止 ForumEngine 时发生异常: {exc}" | 238 | message = f"停止 ForumEngine 时发生异常: {exc}" |
| 242 | logs.append(message) | 239 | logs.append(message) |
| 243 | - logging.exception(message) | 240 | + logger.exception(message) |
| 244 | 241 | ||
| 245 | processes['forum']['status'] = 'stopped' | 242 | processes['forum']['status'] = 'stopped' |
| 246 | 243 | ||
| @@ -292,7 +289,7 @@ def initialize_system_components(): | @@ -292,7 +289,7 @@ def initialize_system_components(): | ||
| 292 | try: | 289 | try: |
| 293 | stop_forum_engine() | 290 | stop_forum_engine() |
| 294 | except Exception: # pragma: no cover | 291 | except Exception: # pragma: no cover |
| 295 | - logging.exception("停止ForumEngine失败") | 292 | + logger.exception("停止ForumEngine失败") |
| 296 | return False, logs, errors | 293 | return False, logs, errors |
| 297 | 294 | ||
| 298 | return True, logs, [] | 295 | return True, logs, [] |
| @@ -749,7 +746,7 @@ def start_app(app_name): | @@ -749,7 +746,7 @@ def start_app(app_name): | ||
| 749 | processes['forum']['status'] = 'running' | 746 | processes['forum']['status'] = 'running' |
| 750 | return jsonify({'success': True, 'message': 'ForumEngine已启动'}) | 747 | return jsonify({'success': True, 'message': 'ForumEngine已启动'}) |
| 751 | except Exception as exc: # pragma: no cover | 748 | except Exception as exc: # pragma: no cover |
| 752 | - logging.exception("手动启动ForumEngine失败") | 749 | + logger.exception("手动启动ForumEngine失败") |
| 753 | return jsonify({'success': False, 'message': f'ForumEngine启动失败: {exc}'}) | 750 | return jsonify({'success': False, 'message': f'ForumEngine启动失败: {exc}'}) |
| 754 | 751 | ||
| 755 | script_path = STREAMLIT_SCRIPTS.get(app_name) | 752 | script_path = STREAMLIT_SCRIPTS.get(app_name) |
| @@ -782,7 +779,7 @@ def stop_app(app_name): | @@ -782,7 +779,7 @@ def stop_app(app_name): | ||
| 782 | processes['forum']['status'] = 'stopped' | 779 | processes['forum']['status'] = 'stopped' |
| 783 | return jsonify({'success': True, 'message': 'ForumEngine已停止'}) | 780 | return jsonify({'success': True, 'message': 'ForumEngine已停止'}) |
| 784 | except Exception as exc: # pragma: no cover | 781 | except Exception as exc: # pragma: no cover |
| 785 | - logging.exception("手动停止ForumEngine失败") | 782 | + logger.exception("手动停止ForumEngine失败") |
| 786 | return jsonify({'success': False, 'message': f'ForumEngine停止失败: {exc}'}) | 783 | return jsonify({'success': False, 'message': f'ForumEngine停止失败: {exc}'}) |
| 787 | 784 | ||
| 788 | success, message = stop_streamlit_app(app_name) | 785 | success, message = stop_streamlit_app(app_name) |
| @@ -947,7 +944,7 @@ def get_config(): | @@ -947,7 +944,7 @@ def get_config(): | ||
| 947 | config_values = read_config_values() | 944 | config_values = read_config_values() |
| 948 | return jsonify({'success': True, 'config': config_values}) | 945 | return jsonify({'success': True, 'config': config_values}) |
| 949 | except Exception as exc: | 946 | except Exception as exc: |
| 950 | - logging.exception("读取配置失败") | 947 | + logger.exception("读取配置失败") |
| 951 | return jsonify({'success': False, 'message': f'读取配置失败: {exc}'}), 500 | 948 | return jsonify({'success': False, 'message': f'读取配置失败: {exc}'}), 500 |
| 952 | 949 | ||
| 953 | 950 | ||
| @@ -971,7 +968,7 @@ def update_config(): | @@ -971,7 +968,7 @@ def update_config(): | ||
| 971 | updated_config = read_config_values() | 968 | updated_config = read_config_values() |
| 972 | return jsonify({'success': True, 'config': updated_config}) | 969 | return jsonify({'success': True, 'config': updated_config}) |
| 973 | except Exception as exc: | 970 | except Exception as exc: |
| 974 | - logging.exception("更新配置失败") | 971 | + logger.exception("更新配置失败") |
| 975 | return jsonify({'success': False, 'message': f'更新配置失败: {exc}'}), 500 | 972 | return jsonify({'success': False, 'message': f'更新配置失败: {exc}'}), 500 |
| 976 | 973 | ||
| 977 | 974 | ||
| @@ -1007,7 +1004,7 @@ def start_system(): | @@ -1007,7 +1004,7 @@ def start_system(): | ||
| 1007 | 'errors': errors | 1004 | 'errors': errors |
| 1008 | }), 500 | 1005 | }), 500 |
| 1009 | except Exception as exc: # pragma: no cover - 保底捕获 | 1006 | except Exception as exc: # pragma: no cover - 保底捕获 |
| 1010 | - logging.exception("系统启动过程中出现异常") | 1007 | + logger.exception("系统启动过程中出现异常") |
| 1011 | _set_system_state(started=False) | 1008 | _set_system_state(started=False) |
| 1012 | return jsonify({'success': False, 'message': f'系统启动异常: {exc}'}), 500 | 1009 | return jsonify({'success': False, 'message': f'系统启动异常: {exc}'}), 500 |
| 1013 | finally: | 1010 | finally: |
| @@ -4,16 +4,12 @@ | @@ -4,16 +4,12 @@ | ||
| 4 | """ | 4 | """ |
| 5 | 5 | ||
| 6 | import time | 6 | import time |
| 7 | -import logging | ||
| 8 | from functools import wraps | 7 | from functools import wraps |
| 9 | -from typing import Callable, Any, Union, List, Type | 8 | +from typing import Callable, Any |
| 10 | import requests | 9 | import requests |
| 11 | -from openai import OpenAI | 10 | +from loguru import logger |
| 12 | 11 | ||
| 13 | # 配置日志 | 12 | # 配置日志 |
| 14 | -logging.basicConfig(level=logging.INFO) | ||
| 15 | -logger = logging.getLogger(__name__) | ||
| 16 | - | ||
| 17 | class RetryConfig: | 13 | class RetryConfig: |
| 18 | """重试配置类""" | 14 | """重试配置类""" |
| 19 | 15 |
-
Please register or login to post a comment