code: def wait_for_task(task_data, task_uri='/tasks'):
      
      taskid = post_task(task_data, task_uri)
  
      if isinstance(task_data, str):
          json_data = json.loads(task_data)
      else:
          json_data = task_data
  
      # inspect the task to see if a timeout is configured
      job = json_data['job'][0]
      env = job.get('credentials')
      task_type = job.get('type')
  
      timeout = TASK_TIMEOUTS.get(env, dict()).get(task_type, DEFAULT_TASK_TIMEOUT)
  
      LOG.debug("Task %s will timeout after %s", task_type, timeout)
  
      return check_task(taskid, timeout)
docs: Run task and check the result.
  
      Args:
          task_data (str): the task json to execute
  
      Returns:
          str: Task status.