code: def wait_for_aip_training_job_completion(
      job_id: Text, project_id: Text
  ) -> bool:
      """Blocks until the AIP Training job is completed and returns the status.
  
      Args:
          job_id: ID for AIP training job.
          project_id: Project under which the AIP Training job is running.
      Returns:
          True if the job succeeded or it was cancelled, False if the job failed.
      """
      # Wait for AIP Training job to finish
      job_name = "projects/{}/jobs/{}".format(project_id, job_id)
      # Disable cache_discovery to remove excessive info logs see:
      # https://github.com/googleapis/google-api-python-client/issues/299
      api_client = discovery.build("ml", "v1", cache_discovery=False)
  
      request = api_client.projects().jobs().get(name=job_name)
  
      response = request.execute()
  
      counter = 0
      logging.info(
          "Waiting for job to complete, polling status every %s sec.",
          _POLL_INTERVAL_IN_SECONDS,
      )
      while response["state"] not in (
          "SUCCEEDED",
          "FAILED",
          "CANCELLED",
      ):
          logging.info(
              "Attempt number %s to retrieve job status.", counter
          )
          counter += 1
          time.sleep(_POLL_INTERVAL_IN_SECONDS)
          response = request.execute()
  
      if response["state"] == "FAILED":
          logging.error(
              "AIP Training job %s failed with error %s.",
              job_id,
              response["errorMessage"],
          )
          return False
  
      # Both CANCELLED and SUCCEEDED status count as successful completion.
      logging.info(
          "AIP Training job %s completed with status %s.",
          job_id,
          response["state"],
      )
      return True
  
imports: import enum
  import json
  import os
  import sys
  import time
  from typing import Dict, Text, Union
  from ..None import version
  from absl import logging
  from googleapiclient import discovery
  from googleapiclient import errors
  from googleapiclient import http
label_desc: Use image node_id 6 for calling a global function with example usage: wait_for_aip_training_job_completion(job_id, project_id) and returns: True, False