Skip to content

Commit

Permalink
Leave the run_cache in a good state after flush_all.
Browse files Browse the repository at this point in the history
Currently this is not important since flush_all is only called
when quiting Fishtest, but it is a good programming practice
to make it self contained.
  • Loading branch information
vdbergh authored and ppigazzini committed Feb 4, 2025
1 parent a7255b0 commit 2a4e69b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions server/fishtest/run_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def buffer(self, run, *, priority=Prio.NORMAL, create=False):
"using priority=Prio.SAVE_NOW has no effect.",
flush=True,
)
return

flush = priority == Prio.SAVE_NOW
run_id = str(run["_id"])
Expand Down Expand Up @@ -156,11 +157,17 @@ def flush_buffers(self):
self.runs.replace_one({"_id": oldest_run_id}, oldest_run)

def flush_all(self):
flush_list = []
with self.run_cache_lock:
for run_id, entry in self.run_cache.items():
if entry["is_changed"]:
with self.active_run_lock(run_id):
self.runs.replace_one({"_id": ObjectId(run_id)}, entry["run"])
entry["is_changed"] = False
entry["last_sync_time"] = time.time()
entry["priority"] = 0
flush_list.append((run_id, entry))
for run_id, entry in flush_list:
with self.active_run_lock(run_id):
self.runs.replace_one({"_id": ObjectId(run_id)}, entry["run"])

def clean_cache(self):
now = time.time()
Expand Down

0 comments on commit 2a4e69b

Please sign in to comment.