fix: 容器重启后第一批任务失败
问题:容器重启时账号对象的 is_running 状态未被重置, 导致新任务提交时被拒绝("任务已在运行中") 修复:在启动流程中添加遗留任务状态清理逻辑 - 重置所有账号的 is_running/should_stop/status - 清理活跃任务句柄 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
19
app.py
19
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("✓ 邮件服务已初始化")
|
||||
|
||||
Reference in New Issue
Block a user