From c6b9783a7a513b6d7b419fab20c38fe5d426cd8a Mon Sep 17 00:00:00 2001 From: DXC Date: Mon, 13 Jul 2026 10:40:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(janitor):=20=E7=A6=81=E6=AD=A2=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E5=9B=A0=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E8=80=8C=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E4=BB=BB=E5=8A=A1=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reconcile_tasks_on_startup() 中有一段逻辑:遍历所有任务,如果 output_dir 在磁盘上不存在,直接 DELETE FROM tasks。这导致重启时如果目录被移动/重命名/ 被之前的 janitor 清理,所有任务记录静默丢失。 修改为仅输出 WARNING 日志,保留数据库记录。用户可通过 DELETE /task/ 手动清理。 --- src/gasflux/janitor.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gasflux/janitor.py b/src/gasflux/janitor.py index 0281b36..0f9a565 100644 --- a/src/gasflux/janitor.py +++ b/src/gasflux/janitor.py @@ -310,8 +310,7 @@ def reconcile_tasks_on_startup(): except Exception as e: current_app.logger.error(f"Failed to delete failed task {task_id}: {str(e)}", exc_info=True) - # Check for tasks with output directories that no longer exist - # This helps clean up database entries for manually deleted directories + # 检查 output_dir 不存在的任务(仅警告,不自动删除) rows = conn.execute(""" SELECT task_id, output_dir FROM tasks @@ -321,18 +320,21 @@ def reconcile_tasks_on_startup(): orphaned_count = 0 for row in rows: - task_id_from_db = row[0] # task_id是第一个字段 - output_dir_from_db = row[1] # output_dir是第二个字段 + task_id_from_db = row[0] + output_dir_from_db = row[1] if not Path(output_dir_from_db).exists(): - conn.execute( - "DELETE FROM tasks WHERE task_id = ?", - (task_id_from_db,) + current_app.logger.warning( + f"Startup reconciliation: Task {task_id_from_db} output directory " + f"not found on disk: {output_dir_from_db}. Database record preserved." ) orphaned_count += 1 if orphaned_count > 0: - current_app.logger.info(f"Startup reconciliation: Marked {orphaned_count} tasks as deleted (directories not found)") + current_app.logger.info( + f"Startup reconciliation: Found {orphaned_count} tasks with missing directories " + f"(records preserved, use DELETE /task/ to manually clean up)" + ) # Backfill output_dir for rows with NULL, using OUTPUT_FOLDER/ output_base = Path(current_app.config.get('OUTPUT_FOLDER') or '')