feat(rohs-check): 新增 RoHS 检核工具进度查询功能及相关接口

This commit is contained in:
hugo committed 2026-06-11 10:05:29 +08:00
1 parent fee33f69d9
commit a18a07ef1a
19 files changed
+654 -58

No files matched your search

+29 -6
View File
@@ -154,12 +154,38 @@ def _run_check_job_loop(
raise RuntimeError("dify_agent_id is set, but Dify api key is missing")
step_logs: list[dict[str, Any]] = []
details: list[dict[str, Any]] = []
success_count = 0
failed_count = 0
skipped_count = 0
all_errors: list[str] = []
def _save_progress(total: int | None = None) -> None:
if run_id is None:
return
try:
from app import db
from app.models import ScheduleRun
progress_run = db.session.get(ScheduleRun, run_id)
if not progress_run or progress_run.status != "running":
return
if total is not None:
progress_run.total_count = max(0, int(total))
progress_run.success_count = success_count
progress_run.failed_count = failed_count
progress_run.skipped_count = skipped_count
db.session.commit()
except Exception as progress_exc:
if current_app:
current_app.logger.warning("[%s] save progress failed run_id=%s error=%s", log_prefix, run_id, progress_exc)
t0 = _ts()
try:
rows = fetch_fn(conn_str)
if max_rows > 0:
rows = rows[:max_rows]
_save_progress(total=len(rows))
step_logs.append(_make_step(
"fetch_srm",
"success",
@@ -175,12 +201,6 @@ def _run_check_job_loop(
))
raise
details: list[dict[str, Any]] = []
success_count = 0
failed_count = 0
skipped_count = 0
all_errors: list[str] = []
for row in rows:
if run_id is not None and is_run_cancelled(run_id):
item = dict(row)
@@ -192,6 +212,7 @@ def _run_check_job_loop(
})
skipped_count += 1
details.append(item)
_save_progress()
continue
item = dict(row)
@@ -215,6 +236,7 @@ def _run_check_job_loop(
failed_count += 1
all_errors.append(pre_result.get("writeback_err", ""))
details.append(item)
_save_progress()
continue
record_text, attachment_url = build_record_fn(conn_str, item, row_id_value)
@@ -339,6 +361,7 @@ def _run_check_job_loop(
item["writeback_err"] = f"{item.get('writeback_err', '')}; writeback failed: {wb_exc}"
details.append(item)
_save_progress()
if len(step_logs) > _MAX_STEP_LOGS_PER_ROW:
step_logs = step_logs[:_MAX_STEP_LOGS_PER_ROW]