Skip to content

Commit

Permalink
Merge pull request #190 from medema-group/hotifx/dump-db-at-end
Browse files Browse the repository at this point in the history
add flag to force save the database to disk
  • Loading branch information
adraismawur authored Oct 10, 2024
2 parents 38ccff5 + 877b80b commit 205b485
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions big_scape/data/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create_in_mem() -> None:
DB.reflect()

@staticmethod
def save_to_disk(db_path: Path) -> None:
def save_to_disk(db_path: Path, force=False) -> None:
"""Saves the in-memory database to a .db file. This overwrites any last database
file in the same location
"""
Expand All @@ -116,7 +116,13 @@ def save_to_disk(db_path: Path) -> None:
click_context = click.get_current_context(silent=True)

if click_context and click_context.obj["no_db_dump"]:
return
# added force to override this override. fun times.
# this is used when you use the --no-db-dump flag so that we can force it
# to save at the end anyway
# TODO: this logic should be moved out, where the no_db_dump flag is checked
# when it is appropriate to do so
if not force:
return

if not DB.opened():
raise DBClosedError()
Expand Down
2 changes: 1 addition & 1 deletion big_scape/run_bigscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,6 @@ def signal_handler(sig, frame):
exec_time = end - start_time

bs_data.DB.set_run_end(run["run_id"], start_time, end)
bs_data.DB.save_to_disk(run["db_path"])
bs_data.DB.save_to_disk(run["db_path"], True)

logging.info("All tasks done at %f seconds", exec_time.total_seconds())

0 comments on commit 205b485

Please sign in to comment.