我正在尝试使用 OperationsClient
get_operation()
函数,以便我可以轮询长时间运行的任务并获取其状态。
代码看起来相当简单:
api = operations_v1.OperationsClient()
response = api.get_operation(name)
但是,OperationClient
的初始化需要一个 channel :OperationsClient(channel)
。我不知道什么是channel是做什么的或者它是如何创建的。
任何帮助表示赞赏。谢谢
最佳答案
来自您链接的文档:
channel
(grpc.Channel) – The gRPC channel associated with the service that implements thegoogle.longrunning.operations
interface.
因此,如果它是您自己的 gRPC 服务,您将需要执行以下操作:
import grpc
channel = grpc.insecure_channel('localhost:50051')
api = operations_v1.OperationsClient(channel)
response = api.get_operation(name)
根据您尝试轮询的长期运行服务,您可能需要改用其 channel 。
关于python - 如何使用 Google Cloud get_operation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55056835/