refactor: 统一脚本任务状态更新
This commit is contained in:
@@ -7,6 +7,7 @@ from threading import Thread
|
|||||||
from fastapi import APIRouter, Body, HTTPException
|
from fastapi import APIRouter, Body, HTTPException
|
||||||
|
|
||||||
from app import state
|
from app import state
|
||||||
|
from app.api.routers.task_runtime import set_task_stage
|
||||||
from app.config import AppConfig, CACHE_DIR, SQL_SCRIPT
|
from app.config import AppConfig, CACHE_DIR, SQL_SCRIPT
|
||||||
from app.processor import DataProcessor, ProcessLogger
|
from app.processor import DataProcessor, ProcessLogger
|
||||||
|
|
||||||
@@ -55,10 +56,10 @@ async def execute_script():
|
|||||||
|
|
||||||
def log_callback(message: str) -> None:
|
def log_callback(message: str) -> None:
|
||||||
logs.append(message)
|
logs.append(message)
|
||||||
state.processing_tasks[task_id] = {"logs": logs.copy(), "status": "processing"}
|
set_task_stage(task_id, "processing", logs)
|
||||||
|
|
||||||
logger = ProcessLogger(log_file=None, callback=log_callback)
|
logger = ProcessLogger(log_file=None, callback=log_callback)
|
||||||
state.processing_tasks[task_id] = {"logs": [], "status": "processing"}
|
set_task_stage(task_id, "processing", logs)
|
||||||
app_config = state.current_config()
|
app_config = state.current_config()
|
||||||
|
|
||||||
thread = Thread(target=_run_script, args=(task_id, logger, logs, app_config), daemon=True)
|
thread = Thread(target=_run_script, args=(task_id, logger, logs, app_config), daemon=True)
|
||||||
@@ -89,10 +90,10 @@ def _run_script(task_id: str, logger: ProcessLogger, logs: list[str], app_config
|
|||||||
processor = DataProcessor(app_config, temp_work_dir, logger)
|
processor = DataProcessor(app_config, temp_work_dir, logger)
|
||||||
processor._execute_sql_script()
|
processor._execute_sql_script()
|
||||||
logger.success("SQL 脚本执行完成")
|
logger.success("SQL 脚本执行完成")
|
||||||
state.processing_tasks[task_id] = {"logs": logs.copy(), "status": "completed"}
|
set_task_stage(task_id, "completed", logs, status="completed")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(f"SQL 脚本执行失败: {exc}")
|
logger.error(f"SQL 脚本执行失败: {exc}")
|
||||||
state.processing_tasks[task_id] = {"logs": logs.copy(), "status": "failed"}
|
set_task_stage(task_id, "failed", logs, status="failed")
|
||||||
finally:
|
finally:
|
||||||
if temp_work_dir and temp_work_dir.exists():
|
if temp_work_dir and temp_work_dir.exists():
|
||||||
shutil.rmtree(temp_work_dir, ignore_errors=True)
|
shutil.rmtree(temp_work_dir, ignore_errors=True)
|
||||||
|
|||||||
@@ -650,3 +650,9 @@
|
|||||||
- A follow-up static import scan removed the leftover unused `Path` import from `app/api/routers/database.py`.
|
- A follow-up static import scan removed the leftover unused `Path` import from `app/api/routers/database.py`.
|
||||||
- Final verification included `.venv\Scripts\python.exe -m compileall app`, `npm run build`, a lightweight Python AST unused-import scan, `.venv\Scripts\python.exe -m pip check`, and `npm audit --omit dev`.
|
- Final verification included `.venv\Scripts\python.exe -m compileall app`, `npm run build`, a lightweight Python AST unused-import scan, `.venv\Scripts\python.exe -m pip check`, and `npm audit --omit dev`.
|
||||||
- Remaining scan hits are intentional runtime/cleanup console messages or behaviorally different format helpers; no further low-risk cleanup item was found in the final pass.
|
- Remaining scan hits are intentional runtime/cleanup console messages or behaviorally different format helpers; no further low-risk cleanup item was found in the final pass.
|
||||||
|
|
||||||
|
## 2026-06-01: Script task status cleanup
|
||||||
|
|
||||||
|
- `app/api/routers/script.py` now reuses the shared `set_task_stage()` helper for manual SQL script task status updates.
|
||||||
|
- Script execution status entries now include the same `stage` field shape used by processing and remote tasks while preserving the existing status values.
|
||||||
|
- Verification performed: `.venv\Scripts\python.exe -m compileall app`, `npm run build`, and `cargo check --manifest-path src-tauri\Cargo.toml` with a temporary sidecar placeholder all passed. Generated build output, Python caches, and temporary Tauri sidecar files were removed after verification.
|
||||||
|
|||||||
Reference in New Issue
Block a user