original_docstring: Ensures the graph with the specified id will exist
docstring: Ensures the graph with the specified id will exist
docstring_tokens: Ensures the graph with the specified id will exist
code: def ensure_graph(runtime_url, pg_id, pg_name, max_attempts=6):
      """Ensures the graph with the specified id will exist"""
      # TODO: Remove this when runtime API more mature
      # Added this attempted delete call here to make sure repeated calls to post
      # flows works by making sure the runtime API main graph is always empty
      try:
          delete_graph(runtime_url)
      except:
          # Probably a 404, doesn't matter
          pass
  
      # The attempts are not *really* attempts because attempts equates to looping
      # twice
      for i in range(0, max_attempts):
          resp = None
  
          try:
              resp = get_graph(runtime_url, pg_id)
          except Exception as e:
              # Assuming you are here because graph needs to be created
              create_graph(runtime_url, pg_id, pg_name)
  
          # TODO: Runtime api only supports 1 graph which is why this check is
          # here. Make sure it will support many graphs and remove this
  
          if resp == None:
              # You are here because the graph was created for first time or
              # the graph was deleted then created. Anyways next loop should
              # check if it got created ok
              continue
          elif resp != None and resp["id"] != pg_id:
              delete_graph(runtime_url)
          elif resp != None and resp["id"] == pg_id:
              return True
  
      return False
code_tokens: def ensure_graph ( runtime_url , pg_id , pg_name , max_attempts = 6 ) : try : delete_graph ( runtime_url ) except : pass for i in range ( 0 , max_attempts ) : resp = None try : resp = get_graph ( runtime_url , pg_id ) except Exception as e : create_graph ( runtime_url , pg_id , pg_name ) if resp == None : continue elif resp != None and resp [ "id" ] != pg_id : delete_graph ( runtime_url ) elif resp != None and resp [ "id" ] == pg_id : return True return False
short_docstring: Ensures the graph with the specified id will exist
short_docstring_tokens: Ensures the graph with the specified id will exist
comment: """Ensures the graph with the specified id will exist"""$SEP$# TODO: Remove this when runtime API more mature$SEP$# Added this attempted delete call here to make sure repeated calls to post$SEP$# flows works by making sure the runtime API main graph is always empty$SEP$# Probably a 404, doesn't matter$SEP$# The attempts are not *really* attempts because attempts equates to looping$SEP$# twice$SEP$# Assuming you are here because graph needs to be created$SEP$# TODO: Runtime api only supports 1 graph which is why this check is$SEP$# here. Make sure it will support many graphs and remove this$SEP$# You are here because the graph was created for first time or$SEP$# the graph was deleted then created. Anyways next loop should$SEP$# check if it got created ok