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

add flag to force save the database to disk #190

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
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())
Loading