Skip to content

Commit

Permalink
adding method to get thr run properties for a run
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Sep 7, 2023
1 parent f40325a commit fd27afa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,25 @@ def update_run_status(self, instance_id: int, uid: str, status: str):
# if there were no errors, commit the updates
if ret_val > -1:
self.commit('asgs')

def get_run_props(self, instance_id: int, uid: str):
"""
gets the run properties for a run
:return:
"""
# create the sql
sql: str = f"SELECT * FROM public.get_run_prop_items_json({instance_id}, '{uid}')"

# get the data
ret_val = self.exec_sql('asgs', sql)

# check the result
if ret_val == -1:
ret_val = ['Run not found']
else:
# replace with the data sorted by keys
ret_val[0]['run_data'] = {x: ret_val[0]['run_data'][x] for x in sorted(ret_val[0]['run_data'])}

# return the data
return ret_val[0]
27 changes: 27 additions & 0 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,33 @@ async def get_the_log_file(log_file: str, search_backups: bool = False):
return JSONResponse(content={'Response': 'Error - You must select a log file.'}, status_code=404, media_type="application/json")


@APP.get("/get_run_properties", dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def get_the_run_properties(instance_id: int, uid: str):
"""
Gets the run properties for the run specified.
"""
# init the returned html status code
status_code = 200

try:
# try to make the call for records
ret_val = db_info.get_run_props(instance_id, uid)

except Exception:
# return a failure message
ret_val = f'Exception detected trying to get the run properties for {instance_id}-{uid}.'

# log the exception
logger.exception(ret_val)

# set the status to a server error
status_code = 500

# return to the caller
return JSONResponse(content=ret_val, status_code=status_code, media_type="application/json")


@APP.get("/get_run_list", dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def get_the_run_list():
"""
Expand Down

0 comments on commit fd27afa

Please sign in to comment.