Compare commits
1 Commits
55cb7fb025
...
1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| c6b9783a7a |
@ -310,8 +310,7 @@ def reconcile_tasks_on_startup():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"Failed to delete failed task {task_id}: {str(e)}", exc_info=True)
|
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
|
# 检查 output_dir 不存在的任务(仅警告,不自动删除)
|
||||||
# This helps clean up database entries for manually deleted directories
|
|
||||||
rows = conn.execute("""
|
rows = conn.execute("""
|
||||||
SELECT task_id, output_dir
|
SELECT task_id, output_dir
|
||||||
FROM tasks
|
FROM tasks
|
||||||
@ -321,18 +320,21 @@ def reconcile_tasks_on_startup():
|
|||||||
|
|
||||||
orphaned_count = 0
|
orphaned_count = 0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
task_id_from_db = row[0] # task_id是第一个字段
|
task_id_from_db = row[0]
|
||||||
output_dir_from_db = row[1] # output_dir是第二个字段
|
output_dir_from_db = row[1]
|
||||||
|
|
||||||
if not Path(output_dir_from_db).exists():
|
if not Path(output_dir_from_db).exists():
|
||||||
conn.execute(
|
current_app.logger.warning(
|
||||||
"DELETE FROM tasks WHERE task_id = ?",
|
f"Startup reconciliation: Task {task_id_from_db} output directory "
|
||||||
(task_id_from_db,)
|
f"not found on disk: {output_dir_from_db}. Database record preserved."
|
||||||
)
|
)
|
||||||
orphaned_count += 1
|
orphaned_count += 1
|
||||||
|
|
||||||
if orphaned_count > 0:
|
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/<id> to manually clean up)"
|
||||||
|
)
|
||||||
|
|
||||||
# Backfill output_dir for rows with NULL, using OUTPUT_FOLDER/<task_id>
|
# Backfill output_dir for rows with NULL, using OUTPUT_FOLDER/<task_id>
|
||||||
output_base = Path(current_app.config.get('OUTPUT_FOLDER') or '')
|
output_base = Path(current_app.config.get('OUTPUT_FOLDER') or '')
|
||||||
|
|||||||
Reference in New Issue
Block a user