def modeltransform_wait(job_id: str, client: Client, output: widgets.Output, wait_interval: int = DEFAULT_WAIT_INTERVAL, wait_timeout: int = DEFAULT_WAIT_TIMEOUT): job_id_output = widgets.Output() update_status_output = widgets.Output() with output: display(job_id_output, update_status_output) with job_id_output: print(f'Wait called on endpoint creation job {job_id}') with update_status_output: beginning_time = datetime.datetime.utcnow() while datetime.datetime.utcnow() - beginning_time < ( datetime.timedelta(seconds=wait_timeout)): update_status_output.clear_output() status_res = client.modeltransform_status(job_id) status_res.raise_for_status() status = status_res.json() if status['status'] in ['Completed', 'Failed', 'Stopped']: print('modeltransform is finished') return status else: print(f'Status is {status["status"]}') print(f'Waiting for {wait_interval} before checking again...') time.sleep(wait_interval)
def modeltransform_status(args: argparse.Namespace, client: Client, output: widgets.Output): if args.wait: return modeltransform_wait(args.job_id, client, output) else: status_res = client.modeltransform_status(args.job_id) status_res.raise_for_status() return status_res.json()