Skip to content

Commit

Permalink
once again, back to on demand DB connections
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Mar 17, 2023
1 parent 488f93f commit f3073b7
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from src.common.pg_impl import PGImplementation

# set the app version
APP_VERSION = 'v0.3.2'
APP_VERSION = 'v0.3.3'

# declare the FastAPI details
APP = FastAPI(title='APSVIZ Settings', version=APP_VERSION)
Expand All @@ -44,9 +44,6 @@
# note the extra comma makes this single item a singleton tuple
db_names: tuple = ('apsviz', 'asgs')

# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# create a DB connection object
db_info_no_auto_commit: PGImplementation = PGImplementation(db_names, _logger=logger, _auto_commit=False)

Expand Down Expand Up @@ -169,6 +166,9 @@ async def display_job_order(workflow_type_name: WorkflowTypeName) -> json:
status_code = 200

try:
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# try to make the call for records
ret_val = db_info.get_job_order(WorkflowTypeName(workflow_type_name).value)

Expand Down Expand Up @@ -214,6 +214,9 @@ async def reset_job_order(workflow_type_name: WorkflowTypeName) -> json:
if ret_val:
raise Exception(f'Failure trying to reset the {WorkflowTypeName(workflow_type_name).value} job order. Error: {ret_val}')

# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# get the new job order
job_order = db_info.get_job_order(WorkflowTypeName(workflow_type_name).value)

Expand Down Expand Up @@ -249,6 +252,9 @@ async def display_job_definitions() -> json:
job_config_data: dict = {}

try:
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# try to make the call for records
job_data = db_info.get_job_defs()

Expand Down Expand Up @@ -321,6 +327,9 @@ async def get_terria_map_catalog_data(grid_type: Union[str, None] = Query(defaul
# add this parm to the list
kwargs.update({param: 'null' if not locals()[param] else f"'{locals()[param]}'"})

# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# try to make the call for records
ret_val: dict = db_info.get_terria_map_catalog_data(**kwargs)
except Exception:
Expand Down Expand Up @@ -389,6 +398,9 @@ async def get_terria_map_catalog_data_file(file_name: Union[str, None] = Query(d
temp_file_path: str = os.path.join(temp_file_path, file_name)

try:
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# try to make the call for records
ret_val: dict = db_info.get_terria_map_catalog_data(**kwargs)

Expand Down Expand Up @@ -453,6 +465,9 @@ async def get_the_run_list():
status_code = 200

try:
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# get the run records
ret_val = db_info.get_run_list()

Expand Down Expand Up @@ -492,6 +507,9 @@ async def set_the_run_status(instance_id: int, uid: str, status: RunStatus = Run
# is this a valid instance id
if instance_id > 0:
try:
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# try to make the update
db_info_no_auto_commit.update_run_status(instance_id, uid, status.value)

Expand Down Expand Up @@ -541,6 +559,9 @@ async def set_the_supervisor_component_image_version(image_repo: ImageRepo, job_

# makesure that the input params are legit
if version_pattern.search(version):
# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# make the update. fix the job name (hyphen) so it matches the DB format
db_info.update_job_image_version(JobTypeName(job_type_name).value + '-',
image_repo_to_repo_name[image_repo] + job_type_to_image_name[job_type_name] + version)
Expand Down Expand Up @@ -610,6 +631,9 @@ async def set_the_supervisor_job_order(workflow_type_name: WorkflowTypeName, job
if job_type_name != 'complete':
job_type_name += '-'

# create a DB connection object
db_info: PGImplementation = PGImplementation(db_names, _logger=logger)

# make the update
db_info.update_next_job_for_job(job_type_name, next_job_type_id, WorkflowTypeName(workflow_type_name).value)

Expand Down

0 comments on commit f3073b7

Please sign in to comment.