From 2f9b1a8eb260400c25c14ba8c8f5c89015f8c895 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 22 Jun 2026 19:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=AF=95=E5=A4=B1=E8=B4=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=B6=E5=A4=8D=E7=94=A8=E6=97=A7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=E5=88=9B=E5=BB=BA=E6=96=B0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重试时查找该账号最近一条失败任务,更新其状态为 pending - 避免同一账号在列表中出现多条重复记录 - 仅复用 failed/error 状态的任务,首次登录仍新建记录 Co-Authored-By: Claude Fable 5 --- web/backend/services/login_service.py | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/web/backend/services/login_service.py b/web/backend/services/login_service.py index 0fb88bd..d8776dd 100644 --- a/web/backend/services/login_service.py +++ b/web/backend/services/login_service.py @@ -156,7 +156,7 @@ class LoginBatchRunner: concurrency = self.concurrency self._push_log("info", f"批量登录任务 {batch_id} 开始,共 {len(self.account_ids)} 个账号,并发数: {concurrency}") - # 创建任务记录(顺序执行,线程安全) + # 创建或复用任务记录(顺序执行,线程安全) task_infos: list[dict] = [] # {task_id, acc_info} for aid in self.account_ids: acc = self.db.query(AccountModel).filter(AccountModel.id == aid).first() @@ -168,13 +168,29 @@ class LoginBatchRunner: self._push_log("warning", f"跳过无权账号: {acc.username}") continue - task = LoginTask( - batch_id=batch_id, - account_id=aid, - status="pending", - created_by=self.created_by, + # 复用该账号最近一条失败任务记录,避免重复产生多条 + existing_task = ( + self.db.query(LoginTask) + .filter(LoginTask.account_id == aid, LoginTask.status.in_(["failed", "error"])) + .order_by(LoginTask.id.desc()) + .first() ) - self.db.add(task) + if existing_task: + existing_task.batch_id = batch_id + existing_task.status = "pending" + existing_task.cookie = "" + existing_task.message = "" + existing_task.finished_at = None + task = existing_task + else: + task = LoginTask( + batch_id=batch_id, + account_id=aid, + status="pending", + created_by=self.created_by, + ) + self.db.add(task) + self.db.flush() # 获取 task.id task_infos.append({