Access long running operation created using AutoML batch-predict only with operation-name and service account credentials

Viewed 160

I'm facing a problem where I am creating a batch prediction operation in GCP AutoML Natural Language. To create the operation (aka. start the batch prediction process) I use the PredictionServiceClient of the google.cloud.automl module. Authentication is done using a service account JSON, whose path is stored in GOOGLE_APPLICATION_CREDENTIALS.

After creating the operation, I fetch the operation name with the purpose of storing it, in order to be able to check the status of the operation at a later point in time.

To check the status of the operation, I want to use the OperationsClient of the module google.api_core.operations_v1, because it can fetch the operation status using the operation name. However, in order to instanciate the OperationsClient, one needs the gRPC channel of the PredictionServiceClient instance, which I didn't find a way to get.

How can I get the gRPC channel "out of my PredictionServiceClient instance", in order to user the OperationsClient, or is there another, easier way to check the state of a long running operation?

Thanks in advance!

PredictionServiceClient: https://googleapis.dev/python/automl/latest/gapic/v1/api.html

OperationsClient: https://googleapis.dev/python/google-api-core/latest/operations_client.html

from google.cloud import automl 
from google.api_core.operations_v1 import OperationsClient

prediction_client = automl.PredictionServiceClient()

response = prediction_client.batch_predict(model_full_id, input_config, output_config)

operation_name = response.operation.name

# How, using the operation_name and service account credentials only,
# can I now access the state of the operation?
1 Answers
Related