From 79a571e58d2e1b1d141449533e7674571d5dab79 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Tue, 23 Dec 2025 23:32:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=B9=E5=99=A8=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E5=90=8E=E7=AC=AC=E4=B8=80=E6=89=B9=E4=BB=BB=E5=8A=A1=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:容器重启时账号对象的 is_running 状态未被重置, 导致新任务提交时被拒绝("任务已在运行中") 修复:在启动流程中添加遗留任务状态清理逻辑 - 重置所有账号的 is_running/should_stop/status - 清理活跃任务句柄 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app.py b/app.py index 21fb550..6c4c447 100644 --- a/app.py +++ b/app.py @@ -208,6 +208,25 @@ if __name__ == "__main__": init_checkpoint_manager() logger.info("✓ 任务断点管理器已初始化") + # 【新增】容器重启时清理遗留的任务状态 + logger.info("清理遗留任务状态...") + try: + from services.state import safe_remove_task, safe_get_active_task_ids, safe_remove_task_status + # 重置所有账号的运行状态 + for _, accounts in safe_iter_user_accounts_items(): + for acc in accounts.values(): + if getattr(acc, "is_running", False): + acc.is_running = False + acc.should_stop = False + acc.status = "未开始" + # 清理活跃任务句柄 + for account_id in list(safe_get_active_task_ids()): + safe_remove_task(account_id) + safe_remove_task_status(account_id) + logger.info("✓ 遗留任务状态已清理") + except Exception as e: + logger.warning(f"清理遗留任务状态失败: {e}") + try: email_service.init_email_service() logger.info("✓ 邮件服务已初始化")