Handling AutoML Long Operations
The Natural language AutoML services offered by the Google Cloud Platform have a few operations that require some time to complete like dataset import, dataset export, dataset delete, model creation, model delete, model deploy, model undeploy, and asynchronous batch predictions.
Google provides email alerts after the completion of the operation to the user if these operations are performed from the UI. However, in case these operations are made using the python client libraries, email notifications are not sent and the initial calls to the APIs are returned right away as and when the call is made while the operations still keep running. However, Google has made available a few ways by which these operations could be handled by the developer.
Using Python
One way you can wait till your operation is still running is to use the response. result() in your python code so that the program waits until the operation is complete.
Using Curl Commands
Another way is to keep polling for your operation. You can keep polling at regular intervals to check if your operation is complete.
Curl command for the same where operation name is projects/{project-id}/locations/us-central1/operations/{operation-id}. You can also get the operation name by using response.operation.name
in your python code where you are making call to the API for the long running operation.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1/operation-name
If you want to wait for a certain time till the execution is complete you can do using the below command where the timeout is the time you want to wait for the operation to complete
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
-d '{"timeout":"timeout"}' \
https://automl.googleapis.com/v1/operation-name:wait
To cancel a running operation
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
https://automl.googleapis.com/v1/operation-name:cancel
More details on handling AutoML long operations can be found at https://cloud.google.com/natural-language/automl/docs/long-operations