|
1 | 1 | """
|
2 | 2 | todo:
|
3 |
| -1. 支持 report API |
4 |
| -2. 缺失文件时临时下载文件处理 |
5 |
| -3. 断连时重新发送 disable 包 |
| 3 | +1. 缺失文件时临时下载文件处理 |
| 4 | +2. 断连时重新发送 disable 包 |
6 | 5 | """
|
7 | 6 |
|
8 | 7 | from core.config import Config
|
|
15 | 14 | from core.orm import writeHits
|
16 | 15 | from core.i18n import locale
|
17 | 16 | from typing import List, Any
|
18 |
| -from aiohttp import web |
| 17 | +from aiohttp import web, ClientResponseError |
| 18 | +from urllib.parse import urljoin |
19 | 19 | from tqdm import tqdm
|
20 | 20 | from pathlib import Path
|
21 | 21 | import toml
|
@@ -245,18 +245,38 @@ async def downloadFile(
|
245 | 245 | if all(results):
|
246 | 246 | pbar.update(len(content))
|
247 | 247 | return
|
| 248 | + |
| 249 | + except ClientResponseError as e: |
| 250 | + logger.terror( |
| 251 | + "cluster.error.download_file.retry", |
| 252 | + file=file.hash, |
| 253 | + e=e.message, |
| 254 | + retry=delay, |
| 255 | + ) |
| 256 | + self.report(e, session) |
| 257 | + |
248 | 258 | except Exception as e:
|
249 | 259 | logger.terror(
|
250 | 260 | "cluster.error.download_file.retry",
|
251 | 261 | file=file.hash,
|
252 | 262 | e=e,
|
253 | 263 | retry=delay,
|
254 | 264 | )
|
| 265 | + |
255 | 266 | await asyncio.sleep(delay)
|
256 | 267 |
|
257 | 268 | logger.terror("cluster.error.download_file.failed", file=file.hash)
|
258 | 269 | self.failed_filelist.files.append(file)
|
259 | 270 |
|
| 271 | + async def report(self, error: ClientResponseError, session: aiohttp.ClientSession) -> None: |
| 272 | + history_urls = [urljoin(self.base_url), *error.history] |
| 273 | + try: |
| 274 | + async with session.post("/openbmclapi/report", data={"url": history_urls, "error": error.message}) as response: |
| 275 | + response.raise_for_status() |
| 276 | + logger.tdebug("cluster.debug.report", url=history_urls) |
| 277 | + except Exception: |
| 278 | + pass |
| 279 | + |
260 | 280 | async def setupRouter(self) -> None:
|
261 | 281 | logger.tinfo("cluster.info.router.creating")
|
262 | 282 | try:
|
|
0 commit comments