fix: 统一处理流程和后台任务显示

- 处理流程抓取失败时记录到失败URL库
- /search页面新增产品处理会话展示区
- 同时显示后台抓取任务和产品处理会话
- 自动刷新同时更新三种数据:任务、会话、失败URL
This commit is contained in:
2026-07-14 15:36:18 +08:00
parent 5e3e9e7335
commit c833394f06
4 changed files with 112 additions and 2 deletions
+12 -2
View File
@@ -102,6 +102,7 @@ class ProcessMonitor:
self._start_step(session_id, product_name, 3, '抓取网页内容')
try:
fetched = []
failed_count = 0
urls_to_fetch = [r['url'] for r in all_data['internet_results'][:5]]
for i, url in enumerate(urls_to_fetch):
@@ -135,12 +136,21 @@ class ProcessMonitor:
logger.info(f"[{session_id}] 已保存到内容库: {title[:30]}")
except Exception as save_error:
logger.warning(f"[{session_id}] 保存内容库失败: {save_error}")
else:
# 记录失败URL
failed_count += 1
error_msg = fetch_result.get('error', '抓取失败')
try:
db.add_failed_url(url, product_name, error_msg, source='process_monitor')
logger.warning(f"[{session_id}] 抓取失败,已记录: {url}")
except Exception as e:
logger.error(f"[{session_id}] 记录失败URL出错: {e}")
time.sleep(0.3)
all_data['fetched_contents'] = fetched
self._complete_step(session_id, 3, {'count': len(fetched)})
logger.info(f"[{session_id}] 步骤3完成: 抓取 {len(fetched)} 个网页")
self._complete_step(session_id, 3, {'count': len(fetched), 'failed': failed_count})
logger.info(f"[{session_id}] 步骤3完成: 抓取 {len(fetched)} 个网页, 失败 {failed_count}")
except Exception as e:
self._fail_step(session_id, 3, str(e))