diff --git a/OpenBench/apps.py b/OpenBench/apps.py index 2a000fb..48ea39e 100644 --- a/OpenBench/apps.py +++ b/OpenBench/apps.py @@ -19,42 +19,6 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # import django.apps -import threading, time - -class ArtifactWatcher(threading.Thread): - - def run(self): - - # Delay imports due to the app not having been loaded yet - import OpenBench.utils - - while True: - - time.sleep(30) - - for test in OpenBench.utils.get_awaiting_tests(): - - dev_has_all = test.dev.source.endswith('artifacts') - base_has_all = test.base.source.endswith('artifacts') - headers = OpenBench.utils.read_git_credentials(test.engine) - - if headers and not dev_has_all: - test.dev.source, dev_has_all = OpenBench.utils.fetch_artifact_url( - test.dev.source, test.engine, headers, test.dev.sha) - test.dev.save() - - if headers and not base_has_all: - test.base.source, base_has_all = OpenBench.utils.fetch_artifact_url( - test.base.source, test.engine, headers, test.base.sha) - test.base.save() - - if dev_has_all and base_has_all: - test.awaiting = False - test.save() - -class OpenbenchConfig(django.apps.AppConfig): +class OpenBench(django.apps.AppConfig): name = 'OpenBench' - - def ready(self): - self.watcher = ArtifactWatcher().start() diff --git a/OpenBench/management/__init__.py b/OpenBench/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/OpenBench/management/commands/__init__.py b/OpenBench/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/OpenBench/management/commands/runserver.py b/OpenBench/management/commands/runserver.py new file mode 100644 index 0000000..977342d --- /dev/null +++ b/OpenBench/management/commands/runserver.py @@ -0,0 +1,51 @@ +import django.apps +import threading, time +import OpenBench.utils + +from django.core.management.commands.runserver import BaseRunserverCommand + +class ArtifactWatcher(threading.Thread): + + def update_test(self, test): + + dev_has_all = test.dev.source.endswith('artifacts') + base_has_all = test.base.source.endswith('artifacts') + headers = OpenBench.utils.read_git_credentials(test.engine) + + if headers and not dev_has_all: + test.dev.source, dev_has_all = OpenBench.utils.fetch_artifact_url( + test.dev.source, test.engine, headers, test.dev.sha) + test.dev.save() + + if headers and not base_has_all: + test.base.source, base_has_all = OpenBench.utils.fetch_artifact_url( + test.base.source, test.engine, headers, test.base.sha) + test.base.save() + + 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(): + self.update_test(test) + + time.sleep(10) + +class Command(BaseRunserverCommand): + + help = "Test" + + def inner_run(self, *args, **options): + self.pre_start() + super().inner_run(*args, **options) + self.pre_quit() + + def pre_start(self): + self.watcher = ArtifactWatcher().start() + + def pre_quit(self): + self.watcher.kill() \ No newline at end of file diff --git a/OpenSite/settings.py b/OpenSite/settings.py index 851299c..7e362f7 100644 --- a/OpenSite/settings.py +++ b/OpenSite/settings.py @@ -36,14 +36,14 @@ MEDIA_URL = '/Media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'Media') INSTALLED_APPS = [ + 'OpenBench', + 'OpenBench.templatetags', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'OpenBench.templatetags', - 'OpenBench.apps.OpenbenchConfig', ] MIDDLEWARE = [