From 2d06e6b1b86527047041a3a69fca0d8c32885705 Mon Sep 17 00:00:00 2001 From: Michel Van den Bergh Date: Sat, 1 Jun 2024 06:12:18 +0000 Subject: [PATCH] Only validate unfinished cache runs Old runs often do not validate due to the existence race conditions in the past. --- server/fishtest/rundb.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index eec86fbba..3b2b32a8e 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -87,13 +87,21 @@ def schedule_tasks(self): self.scheduler.add_task(180.0, self.validate_random_run) def validate_random_run(self): - run_list = list(self.run_cache.values()) + # Excess of caution. Another thread may change run_cache + # while we are iterating over it. + with self.run_cache_lock: + run_list = [ + cache_entry["run"] + for cache_entry in self.run_cache.values() + if not cache_entry["run"]["finished"] + ] if len(run_list) == 0: print( - "Validate_random_run: cache empty. No runs to validate...", flush=True + "Validate_random_run: no unfinished cache runs. No runs to validate...", + flush=True, ) return - run = random.choice(list(run_list))["run"] + run = random.choice(run_list) run_id = str(run["_id"]) try: # Make sure that the run object does not change while we are