code: def _wait_for_operation(
      api: discovery.Resource,
      operation: Dict[str, Any],
      method_name: str,
  ) -> Dict[str, Any]:
      """Wait for a long running operation.
  
      Args:
        api: Google API client resource.
        operation: The operation to wait for.
        method_name: Operation method name for logging.
  
      Returns:
        Operation completion status.
  
      Raises:
        RuntimeError: If the operation completed with an error.
      """
      status_resc = (
          api.projects().operations().get(name=operation["name"])
      )
      while not status_resc.execute().get("done"):
          time.sleep(_POLLING_INTERVAL_IN_SECONDS)
          logging.info("Method %s still being executed...", method_name)
      result = status_resc.execute()
      if result.get("error"):
          # The operation completed with an error.
          raise RuntimeError(
              "Failed to execute {}: {}".format(
                  method_name, result["error"]
              )
          )
      return result
  
file_path: tfx/tfx/extensions/google_cloud_ai_platform/runner.py
imports: import time
  from typing import Any, Dict, List, Optional
  from absl import logging
  from googleapiclient import discovery
  from tfx import types
  from tfx.extensions.google_cloud_ai_platform import prediction_clients
  from tfx.extensions.google_cloud_ai_platform import training_clients
  from tfx.utils import version_utils
label_desc: Use image node_id 2 for calling a global function with example usage: _wait_for_operation(api, operation, method_name) and returns: result