Managing long-running operations

This page describes how to manage the lifecycle of a Cloud Healthcare API long-running operation.

Long-running operations (LROs) are returned when method calls might take a long time to complete. The Cloud Healthcare API creates LROs for several methods. An example is the method to create a dataset, projects.locations.datasets.create. When projects.locations.datasets.create is called, the Cloud Healthcare API creates an LRO to track the dataset creation status. The Cloud Healthcare API provides operations APIs that let you check the status of LROs. You can also list LROs.

LROs are managed at the dataset level. If you are calling a method that returns an LRO, like projects.locations.datasets.dicomStores.import, then to view the LRO's status, make a request to the DICOM store's parent dataset.

In addition to the REST API, the following sources generate long-running operations when you call the methods listed in Methods that return a long-running operation:

You can manage your Cloud Healthcare API LROs using the Google Cloud Console, the gcloud command-line tool, or the REST API.

Note that the record of an LRO is kept for approximately 30 days after the LRO finishes, meaning that you cannot view or list an LRO after that point.

Methods that return a long-running operation

The following methods return an LRO:

Dataset operations:

DICOM operations:

FHIR operations:

Getting details about a long-running operation

The following samples show how to get details about an LRO.

Note that the version of the Cloud Healthcare API shown in the response when getting details about an LRO will be the same as the API version of the method that initiated the LRO.

Console

After calling a method using either the gcloud tool or the API that returns an LRO, you can view details about the LRO in the Cloud Console.

  1. In the Cloud Console, go to the Datasets page.

    Go to the Datasets page

  2. Click the name of the dataset containing the long-running operation you want to view.
  3. Click Operations.

A list of LROs in the dataset and their status displays. To view the error logs in Cloud Logging, click the more information icon in the last column and then click View details in Stackdriver. For more information, see Viewing error logs in Cloud Logging.

gcloud

Suppose that you receive the following response after calling gcloud healthcare datasets deidentify:

Request issued for: [DATASET_ID]
Waiting for operation [OPERATION_ID] to complete...

The response shows that the Cloud Healthcare API created an LRO with an operation ID. The command continues to run until it finishes, at which point it outputs the following:

Request issued for: [DATASET_ID]
Waiting for operation [OPERATION_ID] to complete...done
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID

To get details about an LRO, run the gcloud healthcare operations describe command, specifying the dataset ID and the operation ID.

gcloud healthcare operations describe OPERATION_ID --dataset=DATASET_ID

You can also retrieve the operation ID by listing long-running database operations.

If the request is successful, the command prompt displays the operation details:

done: true
metadata:
'@type': type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata
apiMethodName: google.cloud.healthcare.v1.dataset.DatasetService.DeidentifyDataset
createTime: 'CREATE_TIME'
endTime: 'END_TIME'
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID
response:
'@type': type.googleapis.com/google.cloud.healthcare.v1.dataset.DeidentifySummary

API

To get the status of and view details about an LRO, use the projects.locations.datasets.operations.get method.

curl

To get details about an LRO, make a GET request and provide the name of the dataset, the operation ID, and an access token.

Suppose that you receive the following response after calling projects.locations.datasets.deidentify:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"
}

The name value in the response shows that the Cloud Healthcare API created an LRO named projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID.

The following sample shows how to use a GET request to get details about an LRO using curl.

curl -X GET \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"

You can also retrieve the LRO name by listing long-running database operations.

If the request is successful, the server returns the response in JSON format. When an LRO finishes, the done field will be set to true.

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.DeidentifyDataset",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME",
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
  },
  "done": true,
  "response": {
    "@type": "...",
    "successStoreCount": "SUCCESS_STORE_COUNT"
  }
}

To poll an LRO, repeatedly invoke the projects.locations.datasets.operations.get method until the operation finishes. Use a backoff between each poll request, such as 10 seconds.

PowerShell

To get details about an LRO, make a GET request and provide the name of the dataset, the operation ID, and an access token.

Suppose that you receive the following response after calling projects.locations.datasets.deidentify:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"
}

The name value in the response shows that the Cloud Healthcare API created an LRO named projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID.

The following sample shows how to use a GET request to get details about an LRO using Windows PowerShell.

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID" | Select-Object -Expand Content

You can also retrieve the LRO name by listing long-running database operations.

If the request is successful, the server returns the response in JSON format. When an LRO finishes, the done field will be set to true.

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.DeidentifyDataset",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME",
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
  },
  "done": true,
  "response": {
    "@type": "...",
    "successStoreCount": "SUCCESS_STORE_COUNT"
  }
}

To poll an LRO, repeatedly invoke the projects.locations.datasets.operations.get method until the operation finishes. Use a backoff between each poll request, such as 10 seconds.

Listing long-running operations

The following samples show how to list the long-running operations in a dataset.

Console

After calling methods using gcloud tool or the API that return an LRO, you can view a list of LROs in the Cloud Console.

  1. In the Cloud Console, go to the Datasets page.

    Go to the Datasets page

  2. Click the name of the dataset containing the long-running operation you want to view.
  3. Click Operations.

A list of LROs in the dataset and their status displays. To view the error logs in Cloud Logging, click the more information icon in the last column and then click View details in Stackdriver. For more information, see Viewing error logs in Cloud Logging.

gcloud

To list the LROs in a dataset, run the gcloud healthcare operations list command.

gcloud healthcare operations list \
  --dataset=DATASET_ID \
  --location=LOCATION

If the request is successful, the command prompt lists the LROs:

ID                    LOCATION     DONE
OPERATION_ID          LOCATION       {TRUE|FALSE}
...

API

To list the LROs in a dataset, use the projects.locations.datasets.operations.list method.

curl

To list the LROs in a dataset, make a GET request and provide the dataset name and an access token. The following sample shows a GET request using curl.

curl -X GET \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations"

If the request is successful, the server returns the response in JSON format:

{
  "operations": [
    {
      "name": "PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
        "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.DeidentifyDataset",
        "createTime": "CREATE_TIME",
        "endTime": "END_TIME",
        "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
      },
      "done": true,
      "response": {
        "@type": "...",
        "successStoreCount": "SUCCESS_STORE_COUNT"
      }
    },
    ...
  ]
}

PowerShell

To list the LROs in a dataset, make a GET request and provide the dataset name and an access token. The following sample shows a GET request using Windows PowerShell.

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations" | Select-Object -Expand Content

If the request is successful, the server returns the response in JSON format:

{
  "operations": [
    {
      "name": "PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
        "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.DeidentifyDataset",
        "createTime": "CREATE_TIME",
        "endTime": "END_TIME",
        "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
      },
      "done": true,
      "response": {
        "@type": "...",
        "successStoreCount": "SUCCESS_STORE_COUNT"
      }
    },
    ...
  ]
}

Cancelling long-running operations

The following samples show how to cancel an LRO in a dataset.

Console

After calling a method using either the gcloud tool or the API that returns an LRO, you can cancel it in the Cloud Console while it is still being processed.

  1. In the Cloud Console, go to the Datasets page.

    Go to the Datasets page

  2. Click the name of the dataset containing the long-running operation you want to cancel.
  3. Click Operations.
  4. For the relevant LRO, select Stop Operation from the more information menu in the last column.

API

To cancel the LROs in a dataset, use the projects.locations.datasets.operations.cancel method.

curl

To cancel an LRO in a dataset, make a POST request and specify the following information:

  • The name of the dataset
  • An access token
  • The operation ID
  • The cancel parameter

The following sample shows a POST request using curl.

curl -X POST \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID:cancel"

To view the status of a cancel request, make a GET request and specify the following information:

  • The name of the dataset
  • An access token
  • The operation ID

The following sample shows a GET request using curl.

curl -X GET \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"

If the request is successful, the server returns the response in JSON format:

{
  "name": "PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "API_METHOD_NAME",
    "createTime": "OPERATION_START_TIME",
    "endTime": "OPERATION_END_TIME",
    "cancelRequested": true,
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL",
    "counter": {
      "success": "SUCCESS_COUNT"
    }
  },
  "done": true,
  "error": {
    "code": 1,
    "message": "Operation cancelled by user."
  }
}

PowerShell

To cancel an LRO in a dataset, make a POST request and specify the following information:

  • The name of the dataset
  • An access token
  • The operation ID
  • The cancel parameter

The following sample shows a POST request using Windows PowerShell.

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID:cancel" | Select-Object -Expand Content

To view the status of a cancel request, make a GET request and specify the following information:

  • The name of the dataset
  • An access token
  • The operation ID

The following sample shows a GET request using Windows PowerShell.

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID" | Select-Object -Expand Content

If the request is successful, the server returns the response in JSON format:

{
  "name": "PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "API_METHOD_NAME",
    "createTime": "OPERATION_START_TIME",
    "endTime": "OPERATION_END_TIME",
    "cancelRequested": true,
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL",
    "counter": {
      "success": "SUCCESS_COUNT"
    }
  },
  "done": true,
  "error": {
    "code": 1,
    "message": "Operation cancelled by user."
  }
}