问题描述
我正在调用Google Cloud Function,该函数返回实现google.longrunning.Operations
接口的Operation
对象.我想从另一个仅接收操作名称(将无法访问操作对象本身)的Python进程中轮询该操作.所以我需要类似的东西:
I'm calling a Google Cloud Function that returns an Operation
object implementing the google.longrunning.Operations
interface. I want to poll this operation from another Python process that will only receive the operation name (will not have access to the operation object itself). So I need something like:
operation = getOperation(operationName)
isdone = operation.done()
AFAIK,您无法执行上面的第一步.我在这里找不到它: https://google- cloud-python.readthedocs.io/en/stable/core/operation.html
AFAIK, you can't do the first step above. I haven't found it here: https://google-cloud-python.readthedocs.io/en/stable/core/operation.html
我想按照文档中有关google.longrunning
界面( https://cloud.google.com/speech-to-text/docs/reference/rpc/google.longrunning#google.longrunning.Operations.GetOperation ):
I would like to do what is explained in the docs about the google.longrunning
interface (https://cloud.google.com/speech-to-text/docs/reference/rpc/google.longrunning#google.longrunning.Operations.GetOperation):
rpc GetOperation(GetOperationRequest) returns (Operation)
GetOperationRequest
仅需要操作名称的地方.是否可以使用google-cloud-python
库中的函数重新创建"操作?
Where the GetOperationRequest
simply requires the operation name. Is there a way to "re-create" an operation using functions from the google-cloud-python
library?
推荐答案
您可以使用长时间运行的操作客户端" :
from google.api_core import operations_v1
api = operations_v1.OperationsClient()
name = ...
response = api.get_operation(name)
这篇关于从Google Cloud中的操作名称轮询长时间运行的操作的Python方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!