Working with long-running operations

This page describes how to use the Cloud AutoML to handle long-running operations in AutoML Tables.

Introduction

Some operations in AutoML Tables require some time to complete:

  • datasets.importData
  • datasets.exportData
  • datasets.delete
  • models.batchPredict
  • models.create
  • models.delete
  • models.deploy
  • models.exportEvaluatedExamples
  • models.undeploy

If you are using Google Cloud Platform Console, you can close your browser window without affecting the operation. The panel updates when the operation is complete.

When you make an API call that takes a long time to complete, the initial call returns right away, even though the operation is still running. There are some helper methods you can use to determine the status of a long-running operation.

AutoML Tables sends project owners an email when long-running operations are complete.

Polling for the status of an operation

You can poll for the status of a long-running operation. This approach does not block your program, but you must keep polling until the operation is complete.

To get the operation status, you use the operation ID from the response when you started the operation.

In the command below, replace operation-name with the full name of your operation. The full name has the format projects/{project-id}/locations/us-central1/operations/{operation-id}.

curl -X GET \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/operation-name

You should see output similar to the following for an import operation: In the output, there is a metadata object that contains information specific to the request type. The done field shows whether the operation is complete or not. If the operation is complete, the response contains information about the effect of the request.

{
  "name": "projects/1234/locations/us-central1/operations/TBL2126599795587061786",
  "metadata": {
...
  },
  "done": true,
  "response": {
...
  }
}

Waiting for an operation

If you want to block execution on this operation, you can wait for the operation to complete (or up until a timeout that you specify).

In the command below, replace:

  • operation-name with the full name of your operation. The full name has the format projects/{project-id}/locations/us-central1/operations/{operation-id}.

  • timeout with the maximum amount of time you want to wait, in (fractional) seconds, terminated by "s". For example, "4.5s" causes the wait command to return in four and a half seconds if the operation is still running.

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/v1beta1/operation-name:wait

Canceling an Operation

You can cancel an import or training task using the operation ID. The cancellation is not guaranteed to succeed. Deleting an operation is not supported.

In the command below, replace operation-name with the full name of your operation. The full name has the format projects/{project-id}/locations/us-central1/operations/{operation-id}.

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  https://automl.googleapis.com/v1beta1/operation-name:cancel
هل كانت هذه الصفحة مفيدة؟ يرجى تقييم أدائنا:

إرسال تعليقات حول...

AutoML Tables Documentation