我正在调用Google函数,该函数返回实现Operation接口的google.longrunning.Operations对象。我想从另一个只接收操作名称的Python进程轮询此操作(将无法访问操作对象本身)。所以我需要这样的东西:
operation = getOperation(operationName)
isdone = operation.done()AFAIK,你不能做上面的第一步。我还没在这里找到它: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)的内容:
rpc GetOperation(GetOperationRequest) returns (Operation)其中,GetOperationRequest只需要操作名。是否有一种使用google-cloud-python库中的函数“重新创建”操作的方法?
发布于 2018-11-15 17:37:51
您可以使用get_operation方法的“长期运行的操作客户端”
from google.api_core import operations_v1
api = operations_v1.OperationsClient()
name = ...
response = api.get_operation(name)发布于 2020-04-21 16:43:24
更新最近的客户。您需要使用OperationClient刷新操作:
为了更新现有的操作,您需要将通道传递到OperationClient。
例如,备份一个Firestore数据存储。
from google.cloud import firestore_admin_v1
from google.api_core import operations_v1, grpc_helpers
import time
def main():
client = firestore_admin_v1.FirestoreAdminClient()
channel = grpc_helpers.create_channel(client.SERVICE_ADDRESS)
api = operations_v1.OperationsClient(channel)
db_path = client.database_path('myproject', 'mydb')
operation = client.export_documents(db_path)
current_status = api.get_operation(operation.name)
while current_status.done == False:
time.sleep(5)
current_status = api.get_operation(operation.name)
print('waiting to complete')
print('operation done')发布于 2021-08-18 15:04:35
在我的示例中,AutoML表客户端没有SERVICE_ADDRESS或SCOPE属性,因此不能创建新的gRPC通道。
但是在客户端使用现有的一个似乎是有效的!
from google.api_core import operations_v1
from google.cloud.automl_v1beta1 import TablesClient
automl_tables_client = TablesClient(
credentials=...,
project=...,
region=...,
)
operation_name = ""
grpc_channel = automl_tables_client.auto_ml_client.transport._channel
api_client = operations_v1.OperationsClient(grpc_channel)
response = api_client.get_operation(operation_name)https://stackoverflow.com/questions/53317626
复制相似问题