Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def update_run(
request: Request,
project: str,
uid: str,
iter: int = 0,
db_session: Session = Depends(deps.get_db_session)):
data = None
try:
data = await request.json()
except ValueError:
log_and_raise(HTTPStatus.BAD_REQUEST, reason="bad JSON body")
logger.debug(data)
await run_in_threadpool(get_db().update_run, db_session, data, uid, project, iter=iter)
logger.info("update run: {}".format(data))
return {}
results_tbl.show()
uid = runspec.metadata.uid
proj = (
'--project {}'.format(runspec.metadata.project)
if runspec.metadata.project
else ''
)
print(
'to track results use .show() or .logs() or in CLI: \n'
'!mlrun get run {} {} , !mlrun logs {} {}'.format(uid, proj, uid, proj)
)
if result:
run = RunObject.from_dict(result)
logger.info('run executed, status={}'.format(run.status.state))
if run.status.state == 'error':
if self._is_remote and not self.is_child:
print('runtime error: {}'.format(run.status.error))
raise RunError(run.status.error)
return run
return None
body.data = data
if name.endswith('*'):
body.metadata = client.V1ObjectMeta(generate_name=name[:-1],
namespace=namespace,
labels=labels)
else:
body.metadata = client.V1ObjectMeta(name=name,
namespace=namespace,
labels=labels)
try:
resp = self.v1api.create_namespaced_config_map(namespace, body)
except ApiException as e:
logger.error('failed to create configmap: {}'.format(e))
raise e
logger.info(f'ConfigMap {resp.metadata.name} created')
return resp.metadata.name
def _initialize_db():
global db
if config.httpdb.db_type == "filedb":
logger.info("using FileRunDB")
db = FileDB(config.httpdb.dirpath)
db.initialize(None)
else:
logger.info("using SQLDB")
db = SQLDB(config.httpdb.dsn)
db_session = None
try:
db_session = create_session()
db.initialize(db_session)
finally:
db_session.close()
namespace = namespace or config.namespace
selector = ','.join(['dask.org/component=scheduler'] + selector)
pods = k8s.list_pods(namespace, selector=selector)
status = ''
for pod in pods:
status = pod.status.phase.lower()
print(pod)
if status == 'running':
cluster = pod.metadata.labels.get('dask.org/cluster-name')
logger.info(
'found running dask function {}, cluster={}'.format(
pod.metadata.name, cluster
)
)
return status
logger.info(
'found dask function {} in non ready state ({})'.format(
pod.metadata.name, status
)
)
return status
async def store_function(
request: Request,
project: str,
name: str,
tag: str = "",
versioned: bool = False,
db_session: Session = Depends(deps.get_db_session)):
data = None
try:
data = await request.json()
except ValueError:
log_and_raise(HTTPStatus.BAD_REQUEST, reason="bad JSON body")
logger.debug(data)
logger.info(
"store function: project=%s, name=%s, tag=%s", project, name, tag)
await run_in_threadpool(get_db().store_function, db_session, data, name, project, tag=tag, versioned=versioned)
return {}
def _get_function_status(data):
logger.info("function_status:\n{}".format(data))
selector = data.get("selector")
kind = data.get("kind")
if not selector or not kind:
log_and_raise(HTTPStatus.BAD_REQUEST, reason="runtime error: selector or runtime kind not specified")
resource = runtime_resources_map.get(kind)
if "status" not in resource:
log_and_raise(HTTPStatus.BAD_REQUEST, reason="runtime error: 'status' not supported by this runtime")
resp = None
try:
resp = resource["status"](selector)
logger.info("status: %s", resp)
except Exception as err:
logger.error(traceback.format_exc())
log_and_raise(HTTPStatus.BAD_REQUEST, reason="runtime error: {}".format(err))
schedule = data.get("schedule")
if schedule:
args = (task,)
job_id = get_scheduler().add(schedule, fn, args)
get_db().store_schedule(db_session, data)
response = {"schedule": schedule, "id": job_id}
else:
run = fn.run(task, watch=False)
if run:
response = run.to_dict()
except Exception as err:
logger.error(traceback.format_exc())
log_and_raise(HTTPStatus.BAD_REQUEST, reason="runtime error: {}".format(err))
logger.info("response: %s", response)
return {
"data": response,
}
pod = self.status.build_pod
if not self.status.state == 'ready' and pod:
k8s = self._get_k8s()
status = k8s.get_pod_status(pod)
if logs:
if watch:
status = k8s.watch(pod)
else:
resp = k8s.logs(pod)
if resp:
print(resp.encode())
if status == 'succeeded':
self.status.build_pod = None
self.status.state = 'ready'
logger.info('build completed successfully')
return 'ready'
if status in ['failed', 'error']:
self.status.state = status
logger.error(' build {}, watch the build pod logs: {}'.format(status, pod))
return status
logger.info('builder status is: {}, wait for it to complete'.format(status))
return None