Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove superfluous engine calls #50

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/score_db/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ def submit(self):


def put_experiment(self):
engine = stm.get_engine_from_settings()
session = stm.get_session()

record = exp(
Expand Down Expand Up @@ -440,6 +439,7 @@ def put_experiment(self):
message = f'Attempt to {action} experiment record FAILED'
error_msg = f'Failed to insert/update record - err: {err}'
print(f'error_msg: {error_msg}')
session.close()
else:
message = f'Attempt to {action} experiment record SUCCEEDED'
error_msg = None
Expand All @@ -463,7 +463,6 @@ def put_experiment(self):


def get_experiments(self):
engine = stm.get_engine_from_settings()
session = stm.get_session()

q = session.query(
Expand Down Expand Up @@ -509,11 +508,13 @@ def get_experiments(self):
except Exception as err:
message = 'Request for experiment records FAILED'
error_msg = f'Failed to get experiment records - err: {err}'
session.close()
else:
message = 'Request for experiment records SUCCEEDED'
for idx, row in results.iterrows():
print(f'idx: {idx}, row: {row}')
record_count = len(results.index)
session.close()

details = {}
# details['filters'] = self.filters
Expand Down
2 changes: 2 additions & 0 deletions src/score_db/expt_array_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ def put_expt_array_metrics(self):
session.close()

else:
session.close()
return self.failed_request('No expt array metric records were discovered to be inserted')

return DbActionResponse(
Expand Down Expand Up @@ -770,6 +771,7 @@ def get_expt_array_metrics(self):
columns=ExptArrayMetricsData._fields
)
except Exception as err:
session.close()
trcbk = traceback.format_exc()
msg = f'Problem casting array exeriment metrics query output into pandas ' \
f'DataFrame - err: {trcbk}'
Expand Down
4 changes: 3 additions & 1 deletion src/score_db/expt_file_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ def put_expt_file_counts(self):
message = f'Attempt to insert experiment stored file counts record FAILED'
error_msg = f'Failed to insert record - err: {err}'
print(f'error_msg: {error_msg}')
session.close()
else:
message = f'Attempt to insert experiment stored file counts record SUCCEEDED'
error_msg = None
Expand Down Expand Up @@ -736,5 +737,6 @@ def get_expt_file_counts(self):
)

print(f'response: {response}')


session.close()
return response
1 change: 0 additions & 1 deletion src/score_db/expt_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ def put_expt_metrics_data(self):


def get_experiment_metrics(self):
engine = stm.get_engine_from_settings()
session = stm.get_session()

# set basic query
Expand Down
2 changes: 0 additions & 2 deletions src/score_db/metric_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def submit(self):


def put_metric_type(self):
engine = stm.get_engine_from_settings()
session = stm.get_session()

insert_stmt = insert(mt).values(
Expand Down Expand Up @@ -290,7 +289,6 @@ def put_metric_type(self):


def get_metric_types(self):
engine = stm.get_engine_from_settings()
session = stm.get_session()

q = session.query(
Expand Down
5 changes: 1 addition & 4 deletions src/score_db/score_table_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_engine(user, passwd, host, port, db):

db_engine = create_engine(
url,
pool_size=50,
pool_size=15,
echo=False,
connect_args={"options": "-c timezone=utc"}
)
Expand Down Expand Up @@ -332,7 +332,4 @@ class InstrumentMeta(Base):
Base.metadata.create_all(engine)

def get_session():
engine = get_engine_from_settings()
Session = sessionmaker(bind=engine)

return Session()