fix: dispatcher 串行上传 + 看门狗自动重启 + 线程状态真实检测
- Dispatcher limit=10→1: 一次只传一个视频,传完再传下一个 - 退避缩短: min(30*(n+1),300)s → 失败后更快重试(原 min(60*(n+1)*2,600)s) - /api/status: 用 thread.is_alive() 替代 _running 布尔标志 - 三组件(scheduler/dispatcher/poller)添加 is_alive()+check_and_restart() - app.py 新增 watchdog 线程: 每 60s 检测线程死亡并自动重启
This commit is contained in:
@@ -5,6 +5,8 @@ FAM-Core 主应用 - Flask 单进程
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
from flask import Flask, jsonify
|
||||
|
||||
# 确保包路径
|
||||
@@ -64,14 +66,31 @@ except Exception as e:
|
||||
|
||||
@app.route('/api/status', methods=['GET'])
|
||||
def status():
|
||||
"""系统状态"""
|
||||
"""系统状态(检查线程实际存活)"""
|
||||
return jsonify({
|
||||
"scheduler_running": _scheduler._running if _scheduler else False,
|
||||
"dispatcher_running": _dispatcher._running if _dispatcher else False,
|
||||
"poller_running": _poller._running if _poller else False,
|
||||
"scheduler_running": _scheduler.is_alive() if _scheduler else False,
|
||||
"dispatcher_running": _dispatcher.is_alive() if _dispatcher else False,
|
||||
"poller_running": _poller.is_alive() if _poller else False,
|
||||
}), 200
|
||||
|
||||
|
||||
def _watchdog_run():
|
||||
"""看门狗:每 60s 检查线程存活,崩溃自动重启"""
|
||||
logger.info("Watchdog 线程启动,检查间隔 60s")
|
||||
while True:
|
||||
time.sleep(60)
|
||||
for comp, name in [(_scheduler, 'Scheduler'), (_dispatcher, 'Dispatcher'), (_poller, 'Poller')]:
|
||||
if comp and hasattr(comp, 'check_and_restart'):
|
||||
try:
|
||||
comp.check_and_restart()
|
||||
except Exception as e:
|
||||
logger.error(f"Watchdog 重启 {name} 失败: {e}", exc_info=True)
|
||||
|
||||
|
||||
_watchdog_thread = threading.Thread(target=_watchdog_run, daemon=True, name='watchdog')
|
||||
_watchdog_thread.start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cfg = load_config()
|
||||
port = cfg.get('server', {}).get('port', 8000)
|
||||
|
||||
Reference in New Issue
Block a user