Get the operation status

Stay organized with collections Save and categorize content based on your preferences.

Demonstrate retrieving an operation status.

Code sample



class GetOperationStatus {

  static void getOperationStatus() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String operationFullId = "projects/[projectId]/locations/us-central1/operations/[operationId]";

  // Get the status of an operation
  static void getOperationStatus(String operationFullId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the latest state of a long-running operation.
      Operation operation = client.getOperationsClient().getOperation(operationFullId);

      // Display operation details.
      System.out.println("Operation details:");
      System.out.format("\tName: %s%n", operation.getName());
      System.out.format("\tMetadata Type Url: %s%n", operation.getMetadata().getTypeUrl());
      System.out.format("\tDone: %s%n", operation.getDone());
      if (operation.hasResponse()) {
        System.out.format("\tResponse Type Url: %s%n", operation.getResponse().getTypeUrl());
      if (operation.hasError()) {
        System.out.format("\t\tError code: %s%n", operation.getError().getCode());
        System.out.format("\t\tError message: %s%n", operation.getError().getMessage());


# TODO(developer): Uncomment and set the following variables
# operation_full_id =
#   'projects/<projectId>/locations/<region>/operations/<operationId>'

from import automl_v1beta1 as automl

client = automl.TablesClient()

# Get the latest state of a long-running operation.
op = client.auto_ml_client._transport.operations_client.get_operation(

print("Operation status: {}".format(op))

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.