示例#1
0
def execute_requests(
    requests: Iterable[Tuple[Any, ht.JobSpec, Any]],
    count: Optional[int] = None,
    num_retries: Optional[int] = None,
) -> None:
    """Execute all batches in the supplied generator of batch requests. Results
  aren't returned directly; the callbacks passed to each request when it was
  generated handle any response or exception.

  """
    with u.tqdm_logging() as orig_stream:
        pbar = tqdm.tqdm(
            requests,
            file=orig_stream,
            total=count,
            unit="requests",
            desc="submitting",
            ascii=True,
        )
        for req, spec, cb in pbar:
            pbar.set_description(f'Submitting {spec.spec["jobId"]}')
            execute(req, cb, num_retries=num_retries)
示例#2
0
def execute_jobs(
    job_specs: Iterable[JobSpec],
    dry_run: bool = False,
):
    '''executes a sequence of jobs based on job specs

  Arg:
  job_specs: specifications for jobs to be executed
  dry_run: if True, only print what would be done
  '''

    with u.tqdm_logging() as orig_stream:
        pbar = tqdm.tqdm(logged_job_specs(job_specs),
                         file=orig_stream,
                         total=len(job_specs),
                         ascii=True,
                         unit="experiment",
                         desc="Executing")
        for idx, job_spec in enumerate(pbar, 1):
            command = job_spec.spec['command']
            logging.info(f'Running command: {" ".join(command)}')
            if not dry_run:
                _, ret_code = u.capture_stdout(command, "",
                                               u.TqdmFile(sys.stderr))
            else:
                ret_code = 0
            j = Job(spec=job_spec,
                    container=job_spec.spec['container'],
                    details={'ret_code': ret_code},
                    status=JobStatus.SUCCEEDED
                    if ret_code == 0 else JobStatus.FAILED)
            local_callback(idx=idx, job=j)

    if dry_run:
        logging.info(
            t.yellow(f'\nTo build your image and execute these jobs, '
                     f'run your command again without {c.DRY_RUN_FLAG}\n'))

    return None