MCPcopy
hub / github.com/666ghj/BettaFish / initialize_system_components

Function initialize_system_components

app.py:276–348  ·  view source on GitHub ↗

启动所有依赖组件(Streamlit 子应用、ForumEngine、ReportEngine)。

()

Source from the content-addressed store, hash-verified

274
275
276def initialize_system_components():
277 """启动所有依赖组件(Streamlit 子应用、ForumEngine、ReportEngine)。"""
278 logs = []
279 errors = []
280
281 spider = MindSpider()
282 if spider.initialize_database():
283 logger.info("数据库初始化成功")
284 else:
285 logger.error("数据库初始化失败")
286
287 try:
288 stop_forum_engine()
289 logs.append("已停止 ForumEngine 监控器以避免文件冲突")
290 except Exception as exc: # pragma: no cover - 安全捕获
291 message = f"停止 ForumEngine 时发生异常: {exc}"
292 logs.append(message)
293 logger.exception(message)
294
295 processes['forum']['status'] = 'stopped'
296
297 for app_name, script_path in STREAMLIT_SCRIPTS.items():
298 logs.append(f"检查文件: {script_path}")
299 if os.path.exists(script_path):
300 success, message = start_streamlit_app(app_name, script_path, processes[app_name]['port'])
301 logs.append(f"{app_name}: {message}")
302 if success:
303 startup_success, startup_message = wait_for_app_startup(app_name, 30)
304 logs.append(f"{app_name} 启动检查: {startup_message}")
305 if not startup_success:
306 errors.append(f"{app_name} 启动失败: {startup_message}")
307 else:
308 errors.append(f"{app_name} 启动失败: {message}")
309 else:
310 msg = f"文件不存在: {script_path}"
311 logs.append(f"错误: {msg}")
312 errors.append(f"{app_name}: {msg}")
313
314 forum_started = False
315 try:
316 start_forum_engine()
317 processes['forum']['status'] = 'running'
318 logs.append("ForumEngine 启动完成")
319 forum_started = True
320 except Exception as exc: # pragma: no cover - 保底捕获
321 error_msg = f"ForumEngine 启动失败: {exc}"
322 logs.append(error_msg)
323 errors.append(error_msg)
324
325 if REPORT_ENGINE_AVAILABLE:
326 try:
327 if initialize_report_engine():
328 logs.append("ReportEngine 初始化成功")
329 else:
330 msg = "ReportEngine 初始化失败"
331 logs.append(msg)
332 errors.append(msg)
333 except Exception as exc: # pragma: no cover

Callers 1

start_systemFunction · 0.85

Calls 10

initialize_databaseMethod · 0.95
MindSpiderClass · 0.90
initialize_report_engineFunction · 0.90
stop_forum_engineFunction · 0.85
start_streamlit_appFunction · 0.85
wait_for_app_startupFunction · 0.85
start_forum_engineFunction · 0.85
cleanup_processesFunction · 0.85
existsMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected