def main()

in python-batch/batch.py [0:0]


def main(argv):
  """
  This is where the Job and Pubsub objects are created and used.

  :param argv: Standard commandline arguments
  :type argv: _type_
  """

  # Read in config file. 
  config = parse_yaml_file(FLAGS.config_file)

  # Create unique job ID, required for Batch and k8s Jobs
  job_id = config["job_prefix"] + uuid.uuid4().hex[:8]

  # "previous_job_id": Used for Pubsub. TOPIC is created from JobID, a restart can provide an existing Job
  # Id for existing pubsub queue
  # TODO: support more env_vars

  env_vars = {}
  if FLAGS.previous_job_id:
    env_vars = dict(env_vars, TOPIC_ID = FLAGS.previous_job_id)
  else:
    env_vars = dict(env_vars, TOPIC_ID = job_id)

  # Create jobs object
  jobs = CloudBatchJobs(job_id, config, env_vars)


  # If pubsub queue is required 
  if FLAGS.pubsub and not FLAGS.debug:

    pubsub = PubSub(job_id, config, previous_job_id=FLAGS.previous_job_id)
    pubsub.create_topic()
    pubsub.create_subscription()
    pubsub.publish_fifo_ids()

  # Delete job. JobID must be passed.
  if(FLAGS.delete_job):
    print("Deleting job", file=sys.stderr)
    deleted_job = jobs.delete_job(FLAGS.delete_job)
    print(deleted_job.result, file=sys.stderr)
    exit()

  # Prints list of jobs, in queue, running or complteted.
  if(FLAGS.list_jobs):
    print("Listing jobs", file=sys.stderr)
    job_list = jobs.list_jobs()

    for job in job_list:
      print(job.name,"\t",job.status.state, file=sys.stderr)
    exit()

  # Prints 
  if FLAGS.debug:
    print(config, file=sys.stderr)
    
  if FLAGS.create_job:
    # Create the job
    print(jobs.client.create_job(jobs.create_job_request()), file=sys.stderr)
  else:
    print(jobs.create_job_request().job, file=sys.stderr)