fix: 任务队列改从 app.chat_download_config 动态构造,解决 os.execv重启后 _task_queue全局变量丢失导致队列只显示 1 个频道的问题
部署到群晖 / deploy (push) Successful in 41s
部署到群晖 / deploy (push) Successful in 41s
This commit is contained in:
@@ -200,11 +200,37 @@ def get_download_speed():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _compute_current_task_queue() -> list:
|
||||||
|
"""动态构造当前任务队列。
|
||||||
|
由于 restart 走 os.execv,download_stat 里的 _task_queue 全局变量会丢;
|
||||||
|
所以真实来源以 _app.chat_download_config(config.yaml 重载后的结果)为准,
|
||||||
|
chat_title 从 channel_history 查。
|
||||||
|
"""
|
||||||
|
global _app
|
||||||
|
if not _app or not _app.chat_download_config:
|
||||||
|
return []
|
||||||
|
history_map = {}
|
||||||
|
for h in _load_channel_history():
|
||||||
|
cid = str(h.get("chat_id", "") or "")
|
||||||
|
if cid:
|
||||||
|
history_map[cid] = h.get("chat_title", "") or cid
|
||||||
|
queue = []
|
||||||
|
for chat_id in _app.chat_download_config.keys():
|
||||||
|
cid_str = str(chat_id)
|
||||||
|
queue.append({
|
||||||
|
"chat_id": cid_str,
|
||||||
|
"chat_title": history_map.get(cid_str, cid_str),
|
||||||
|
})
|
||||||
|
return queue
|
||||||
|
|
||||||
|
|
||||||
@_flask_app.route("/api/task_progress")
|
@_flask_app.route("/api/task_progress")
|
||||||
@login_required
|
@login_required
|
||||||
def api_task_progress():
|
def api_task_progress():
|
||||||
"""Get current task progress including skipped files"""
|
"""Get current task progress including skipped files"""
|
||||||
progress = get_task_progress()
|
progress = get_task_progress()
|
||||||
|
# 覆盖 task_queue:download_stat 里的全局变量在 os.execv 重启后会丢,用 app 动态算才稳
|
||||||
|
progress["task_queue"] = _compute_current_task_queue()
|
||||||
return jsonify(progress)
|
return jsonify(progress)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user