Skip to content

Commit

Permalink
ignore error in __del__, set status to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasHeger committed Mar 29, 2022
1 parent 27c96a4 commit cc94282
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/daisy/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ def upload_metrics_tables(infiles: list,
pool.join()


def mark_upload_complete(url: str, run_id: int):
engine = create_engine(url)
session = sessionmaker(bind=engine)()
benchmark_run = session.query(BenchmarkRun).filter_by(id=run_id).first()
benchmark_run.status = "complete"
session.commit()


def upload_result(infiles, outfile, *extras):
"""upload results into database.
Expand Down Expand Up @@ -729,9 +737,7 @@ def upload_result(infiles, outfile, *extras):
# schema=None,
# is_sqlite3=is_sqlite3)

# benchmark_run.status = "complete"
# session.commit()

mark_upload_complete(url, benchmark_run.id)

logger.info("uploaded results under run_id {}".format(benchmark_run.id))
touch(outfile)
Expand Down
7 changes: 6 additions & 1 deletion src/daisy/table_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ def close(self):
if self.database_url is None:
return

engine = create_engine(self.database_url)
try:
engine = create_engine(self.database_url)
except AttributeError:
# do not create indices if sqlalchemy already shut down
return

if not self.have_created_indices:
for index_name, info in self.indices.items():
table_name, fields = info
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def benchmark_layout(tmp_path):

ntools = 2
nmetrics = 2000
nmetrics = 1000

tools = [f"tool{x}" for x in range(ntools)]
metrics = [f"metric{x}" for x in range(nmetrics)]
Expand Down Expand Up @@ -76,6 +76,8 @@ def test_upload(benchmark_layout, tmp_path, max_workers):
run_df = pandas.read_sql("SELECT * FROM run", conn)
assert len(run_df) == 1

assert run_df.status[0] == "complete"

with db_engine.connect() as conn:
ins_df = pandas.read_sql("SELECT * FROM instance", conn)
assert list(ins_df.run_id.unique()) == [1]
Expand Down

0 comments on commit cc94282

Please sign in to comment.