作者:我木良心c | 来源:互联网 | 2022-12-05 21:59
详情如下:https://issuetracker.google.com/issues/113672049
交叉发布在这里:https://github.com/GoogleCloudPlatform/google-cloud-python/issues/5879)
从Python中的Google Cloud功能使用Firebase存储API时,我收到连接重置错误.
部署的函数调用一个blob-get ie
from firebase_admin import storage
def fn(request):
bucket = 'my-firebase-bucket'
path = '/thing'
blob = storage.bucket(bucket).get_blob(path)
失败是间歇性的; 该功能的成功率约为90%.
在部署后第一次调用函数时,似乎更有可能失败.
1> timvink..:
云功能是无状态的,但是可以重用先前调用中的全局状态。提示和这些文档中对此进行了说明。
将全局状态与重试一起使用应为您提供更强大的功能:
from tenacity import retry, stop_after_attempt, wait_random
from firebase_admin import storage
@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_bucket(storage):
return storage.bucket('my-firebase-bucket')
@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_blob(bucket, path):
return bucket.get_blob(path)
bucket = get_bucket(storage)
def fn(request):
path = '/thing'
blob = get_blob(bucket, path)
# etc..