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))