fix: expose match live stream task error on failure
This commit is contained in:
@@ -89,6 +89,24 @@ def _fetch_stream_payload(source_url: str, now_ts: int) -> Dict[str, str]:
|
||||
return parse_match_live_detail_html(response.text)
|
||||
|
||||
|
||||
def _build_run_result(candidate_count: int, success_count: int, failed_count: int) -> Dict[str, Any]:
|
||||
summary_text = (
|
||||
f"赛事直播流抓取完成: 待处理 {candidate_count} 条, "
|
||||
f"成功 {success_count} 条, 失败 {failed_count} 条"
|
||||
)
|
||||
result = {
|
||||
"success": failed_count == 0,
|
||||
"candidate_count": candidate_count,
|
||||
"saved_count": success_count,
|
||||
"count": success_count,
|
||||
"failed_count": failed_count,
|
||||
"summary_text": summary_text,
|
||||
}
|
||||
if failed_count > 0:
|
||||
result["error"] = f"赛事直播流抓取存在失败线路: 失败 {failed_count} 条"
|
||||
return result
|
||||
|
||||
|
||||
class TaskFileLock:
|
||||
def __init__(self, name: str, lock_dir: Path | None = None):
|
||||
safe_name = "".join(ch if ch.isalnum() or ch in ("-", "_") else "_" for ch in str(name or "task"))
|
||||
@@ -244,17 +262,7 @@ def run(db_config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
failed_count += 1
|
||||
|
||||
candidate_count = len(rows)
|
||||
return {
|
||||
"success": failed_count == 0,
|
||||
"candidate_count": candidate_count,
|
||||
"saved_count": success_count,
|
||||
"count": success_count,
|
||||
"failed_count": failed_count,
|
||||
"summary_text": (
|
||||
f"赛事直播流抓取完成: 待处理 {candidate_count} 条, "
|
||||
f"成功 {success_count} 条, 失败 {failed_count} 条"
|
||||
),
|
||||
}
|
||||
return _build_run_result(candidate_count, success_count, failed_count)
|
||||
finally:
|
||||
repo.close()
|
||||
lock.release()
|
||||
|
||||
Reference in New Issue
Block a user