8000 chore: 优化上传文件 · TTB-Network/python-openbmclapi@baa680c · GitHub
[go: up one dir, main page]

Skip to content

Commit baa680c

Browse files
committed
chore: 优化上传文件
1 parent b2cff1a commit baa680c

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ config
77
cache
88
database/*.db
99

10-
**/__pycache__
10+
**/__pycache__
11+
12+
# pyenv
13+
.python-version
14+
.python-version.lock
15+
pyenv/

core/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ async def main():
9393
# serve
9494
await clusters.serve()
9595

96-
except asyncio.CancelledError:
97-
...
9896
except:
9997
logger.debug_traceback()
10098

core/cluster.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ async def _download_file(
518518
if hash.hexdigest() != file.hash or size != file.size:
519519
await anyio.sleep(50)
520520
raise Exception(f"hash mismatch, got {hash.hexdigest()} expected {file.hash}")
521-
521+
522522
except Exception as e:
523523
last_error = e
524524
self._pbar.update(-size)
@@ -545,11 +545,18 @@ async def upload_storage(
545545
return
546546
for storage in missing_storage:
547547
tmp_file.seek(0)
548-
await storage.storage.upload(f"download/{file.hash[:2]}/{file.hash}", tmp_file, size)
549-
550-
551-
552-
548+
retries = 0
549+
while 1:
550+
try:
551+
await storage.storage.upload(f"download/{file.hash[:2]}/{file.hash}", tmp_file, size)
552+
break
553+
except:
554+
if retries >= 10:
555+
raise
556+
retries += 1
557+
next = 10 * (retries + 1)
558+
logger.twarning("storage.retry_upload", name=storage.storage.name, times=retries, time=next)
559+
await anyio.sleep(next)
553560

554561
async def get_configurations(self):
555562
configurations: list[OpenBMCLAPIConfiguration] = await concurrency.gather(*[

locale/zh_cn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
"info.web.forward.pub_port": "公共端口 [${port}]",
4141
"success.cluster.keepalive": "节点 [${id}] 服务了 [${hits}] 个文件 总计 [${bytes}iB] 延迟 [${delay}ms]",
4242
"warning.cluster.keepalive": "节点 [${id}] 保活失败 (${failed}/3)",
43-
"warning.cluster.warden": "节点 [${id}] 巡检:[${msg}]"
43+
"warning.cluster.warden": "节点 [${id}] 巡检:[${msg}]",
44+
"warning.storage.retry_upload": "存储 [${name}] 上传失败 [${times}] 次,将在 [${time}] 秒后重试"
4445
}

0 commit comments

Comments
 (0)
0