From 4c2e669fa2c09df077fd17c16f01e84fdd36fef8 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 5 Aug 2023 21:02:28 -0400 Subject: [PATCH] Resolve cross-engine artifact waiting bug If waiting for artifacts after test creation, the public engine would appear to still be waiting for artifacts infinitely. This resolves that by identifying public engine sources and considering that as being ready --- OpenBench/management/commands/runserver.py | 61 +++++++------------- OpenBench/watcher.py | 66 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 OpenBench/watcher.py diff --git a/OpenBench/management/commands/runserver.py b/OpenBench/management/commands/runserver.py index 14a4229..b8d1daa 100644 --- a/OpenBench/management/commands/runserver.py +++ b/OpenBench/management/commands/runserver.py @@ -1,45 +1,26 @@ -import django.apps -import requests, sys, threading, time -import OpenBench.utils +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# OpenBench is a chess engine testing framework authored by Andrew Grant. # +# # +# # +# OpenBench is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# OpenBench is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +from OpenBench.watcher import ArtifactWatcher from django.core.management.commands.runserver import Command as BaseRunserverCommand -class ArtifactWatcher(threading.Thread): - - def check_for_artifacts(self, data): - return OpenBench.utils.fetch_artifact_url(*data) - - def update_test(self, test): - - # Check for Artifacts for Dev - if not (dev_has_all := test.dev.source.endswith('artifacts')): - dev_headers = OpenBench.utils.read_git_credentials(test.dev_engine) - data = [test.dev.source, test.dev_engine, dev_headers, test.dev.sha] - test.dev.source, dev_has_all = self.check_for_artifacts(data) - test.dev.save() - - # Check for Artifacts for Base - if not (base_has_all := test.base.source.endswith('artifacts')): - base_headers = OpenBench.utils.read_git_credentials(test.base_engine) - data = [test.base.source, test.base_engine, base_headers, test.base.sha] - test.base.source, base_has_all = self.check_for_artifacts(data) - test.base.save() - - # If both finished, flag the test as no longer awaiting - if dev_has_all and base_has_all: - test.awaiting = False - test.save() - - def run(self): - while True: - for test in OpenBench.utils.get_awaiting_tests(): - try: self.update_test(test) - except: - import traceback, sys - traceback.print_exc() - sys.stdout.flush() - time.sleep(15) - class Command(BaseRunserverCommand): def inner_run(self, *args, **options): @@ -51,4 +32,4 @@ class Command(BaseRunserverCommand): self.watcher = ArtifactWatcher().start() def pre_quit(self): - self.watcher.kill() + self.watcher.kill() \ No newline at end of file diff --git a/OpenBench/watcher.py b/OpenBench/watcher.py new file mode 100644 index 0000000..dfde9c5 --- /dev/null +++ b/OpenBench/watcher.py @@ -0,0 +1,66 @@ +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# OpenBench is a chess engine testing framework authored by Andrew Grant. # +# # +# # +# OpenBench is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# OpenBench is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +import requests +import sys +import threading +import time +import traceback + +import OpenBench.utils + +class ArtifactWatcher(threading.Thread): + + def update_test(self, test): + + # Public engines end their source with .zip. Private engines end + # their source with /artifacts, iff the artifacts have been found + + dev_has = test.dev.source.endswith('artifacts') + dev_has = test.dev.source.endswith('.zip') or dev_has + + base_has = test.base.source.endswith('artifacts') + base_has = test.base.source.endswith('.zip') or base_has + + if not dev_has: # Check for new Artifacts for Dev + dev_headers = OpenBench.utils.read_git_credentials(test.dev_engine) + data = [test.dev.source, test.dev_engine, dev_headers, test.dev.sha] + test.dev.source, dev_has = OpenBench.utils.fetch_artifact_url(*data) + test.dev.save() + + if not base_has: # Check for new Artifacts for Base + base_headers = OpenBench.utils.read_git_credentials(test.base_engine) + data = [test.base.source, test.base_engine, base_headers, test.base.sha] + test.base.source, base_has = OpenBench.utils.fetch_artifact_url(*data) + test.base.save() + + # If both finished, flag the test as no longer awaiting + if dev_has and base_has: + test.awaiting = False + test.save() + + def run(self): + while True: + for test in OpenBench.utils.get_awaiting_tests(): + try: self.update_test(test) + except: + traceback.print_exc() + sys.stdout.flush() + time.sleep(15)