From 0c9f9b6d3c481be9584ebcce8605054700f482c4 Mon Sep 17 00:00:00 2001 From: ZhuoZhou Date: Thu, 4 Sep 2025 15:44:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E9=87=8D=E8=AF=95=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build_package/upload_firebase_storage.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/FindObjectBundleBuilder/Tools/build_package/upload_firebase_storage.py b/FindObjectBundleBuilder/Tools/build_package/upload_firebase_storage.py index 9bc0f22..abb25cb 100644 --- a/FindObjectBundleBuilder/Tools/build_package/upload_firebase_storage.py +++ b/FindObjectBundleBuilder/Tools/build_package/upload_firebase_storage.py @@ -50,6 +50,21 @@ def upload_single_file(helper, storage_file, local_file, blob_dic, ext_meta={}): print(local_file + " 上传失败,尝试重试,错误信息:" + repr(e)) upload_single_file(helper, storage_file, local_file, blob_dic, ext_meta) +def upload_file_with_retry(helper, storage_file, file_path, max_retries=3): + """带重试机制的文件上传函数""" + for attempt in range(max_retries): + try: + print(f"{file_path} 上传中..") + helper.upload_file_no_metadata(storage_file, file_path) + return + except Exception as e: + if attempt < max_retries - 1: + print(f"{file_path} 上传失败,尝试重试 ({attempt + 1}/{max_retries}),错误信息:{repr(e)}") + time.sleep(2) # 重试前等待2秒 + else: + print(f"{file_path} 上传失败,已达到最大重试次数,错误信息:{repr(e)}") + raise + def get_psd_id(ab_name): arr = ab_name.split("_") return int(arr[len(arr) - 1].split(".")[0]) @@ -78,7 +93,7 @@ def upload_directory(helper, storage_path, local_path, filter, ext_meta={}): upload_single_file(helper, storage_file, file_path, {}, ext_meta) clear_cdn_tool.appendClearFile(storage_file) else: - helper.upload_file_no_metadata(storage_file, file_path) + upload_file_with_retry(helper, storage_file, file_path) # 每个文件上传后间隔1秒 time.sleep(1) print("上传完成Package资源 Local: {} Storage: {}".format(local_path, storage_path))