Handle re-triggering workflows
In the event of expired artifacts, or a Github bug where the REST API returns a list of completed jobs, yet no artifacts, even though they are present through the website
This commit is contained in:
1 parent
ef1f23503b
commit
df2b0fb0a3
2 files changed
+52
-22
No files matched your search
@@ -1,29 +1,46 @@
|
|||||||
import django.apps
|
import django.apps
|
||||||
import threading, time
|
import requests, sys, threading, time
|
||||||
import OpenBench.utils
|
import OpenBench.utils
|
||||||
|
|
||||||
from django.core.management.commands.runserver import Command as BaseRunserverCommand
|
from django.core.management.commands.runserver import Command as BaseRunserverCommand
|
||||||
|
|
||||||
class ArtifactWatcher(threading.Thread):
|
class ArtifactWatcher(threading.Thread):
|
||||||
|
|
||||||
|
def check_for_artifacts(self, data):
|
||||||
|
|
||||||
|
# Success, if we had all artifacts. Otherwise consider re-running the Workflow
|
||||||
|
retval, has_all = OpenBench.utils.fetch_artifact_url(*data, return_data=True)
|
||||||
|
if has_all: return retval, True
|
||||||
|
|
||||||
|
# Otherwise, we may have returned the Jobs + Artifacts
|
||||||
|
jobs, artifacts = retval
|
||||||
|
|
||||||
|
# Catch expired artifacts, or a Github API bug and run the Workflow
|
||||||
|
if all(job['conclusion'] == 'success' for job in jobs):
|
||||||
|
run_id = jobs[0]['run_id']
|
||||||
|
url = OpenBench.utils.path_join(data[0], 'actions', 'runs', str(run_id), 'rerun')
|
||||||
|
requests.post(url=url, headers=data[2]).json()
|
||||||
|
|
||||||
|
# We did not have all artifacts needed, return the original source
|
||||||
|
return data[0], False
|
||||||
|
|
||||||
def update_test(self, test):
|
def update_test(self, test):
|
||||||
|
|
||||||
dev_has_all = test.dev.source.endswith('artifacts')
|
# Check for Artifacts for Dev, and re-run if needed
|
||||||
base_has_all = test.base.source.endswith('artifacts')
|
if not (dev_has_all := test.dev.source.endswith('artifacts')):
|
||||||
|
|
||||||
dev_headers = OpenBench.utils.read_git_credentials(test.dev_engine)
|
dev_headers = OpenBench.utils.read_git_credentials(test.dev_engine)
|
||||||
base_headers = OpenBench.utils.read_git_credentials(test.base_engine)
|
data = [test.dev.source, test.dev_engine, dev_headers, test.dev.sha]
|
||||||
|
test.dev.source, dev_has_all = self.check_for_artifacts(data)
|
||||||
if dev_headers and not dev_has_all:
|
|
||||||
test.dev.source, dev_has_all = OpenBench.utils.fetch_artifact_url(
|
|
||||||
test.dev.source, test.dev_engine, dev_headers, test.dev.sha)
|
|
||||||
test.dev.save()
|
test.dev.save()
|
||||||
|
|
||||||
if base_headers and not base_has_all:
|
# Check for Artifacts for Base, and re-run if needed
|
||||||
test.base.source, base_has_all = OpenBench.utils.fetch_artifact_url(
|
if not (base_has_all := test.base.source.endswith('artifacts')):
|
||||||
test.base.source, test.base_engine, base_headers, test.base.sha)
|
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()
|
test.base.save()
|
||||||
|
|
||||||
|
# If both finished, flag the test as no longer awaiting
|
||||||
if dev_has_all and base_has_all:
|
if dev_has_all and base_has_all:
|
||||||
test.awaiting = False
|
test.awaiting = False
|
||||||
test.save()
|
test.save()
|
||||||
@@ -31,8 +48,12 @@ class ArtifactWatcher(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
for test in OpenBench.utils.get_awaiting_tests():
|
for test in OpenBench.utils.get_awaiting_tests():
|
||||||
self.update_test(test)
|
try: self.update_test(test)
|
||||||
time.sleep(10)
|
except:
|
||||||
|
import traceback, sys
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.stdout.flush()
|
||||||
|
time.sleep(15)
|
||||||
|
|
||||||
class Command(BaseRunserverCommand):
|
class Command(BaseRunserverCommand):
|
||||||
|
|
||||||
|
|||||||
+17
-8
@@ -296,7 +296,7 @@ def collect_github_info(request, errors, field):
|
|||||||
url, has_all = fetch_artifact_url(base, engine, headers, data['sha'])
|
url, has_all = fetch_artifact_url(base, engine, headers, data['sha'])
|
||||||
return (url, branch, data['sha'], bench), has_all
|
return (url, branch, data['sha'], bench), has_all
|
||||||
|
|
||||||
def fetch_artifact_url(base, engine, headers, sha):
|
def fetch_artifact_url(base, engine, headers, sha, return_data=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Fetch the run id for the openbench workflow for this comment
|
# Fetch the run id for the openbench workflow for this comment
|
||||||
@@ -304,17 +304,26 @@ def fetch_artifact_url(base, engine, headers, sha):
|
|||||||
url += '?head_sha=%s' % (sha)
|
url += '?head_sha=%s' % (sha)
|
||||||
run_id = requests.get(url=url, headers=headers).json()['workflow_runs'][0]['id']
|
run_id = requests.get(url=url, headers=headers).json()['workflow_runs'][0]['id']
|
||||||
|
|
||||||
# Construct the final URL that will be used to look at artifacts
|
# Fetch information about individual job results
|
||||||
|
url = path_join(base, 'actions', 'runs', str(run_id), 'jobs')
|
||||||
|
jobs = requests.get(url=url, headers=headers).json()['jobs']
|
||||||
|
|
||||||
|
# Fetch information about individual artifact
|
||||||
url = path_join(base, 'actions', 'runs', str(run_id), 'artifacts')
|
url = path_join(base, 'actions', 'runs', str(run_id), 'artifacts')
|
||||||
artifacts = requests.get(url=url, headers=headers).json()['artifacts']
|
artifacts = requests.get(url=url, headers=headers).json()['artifacts']
|
||||||
|
|
||||||
# Verify that all of the artifacts exist and are not expired
|
# All jobs finished, with an associated, non-expired Artifact
|
||||||
available = [ f['name'] for f in artifacts if f['expired'] == False ]
|
error = any(job['conclusion'] != 'success' for job in jobs)
|
||||||
required = OPENBENCH_CONFIG['engines'][engine]['build']['artifacts']
|
error = error or any(artifact['expired'] for artifact in artifacts)
|
||||||
has_all = all(['%s-%s' % (sha, name) in available for name in required])
|
error = error or len(jobs) != len(artifacts)
|
||||||
|
|
||||||
# Return the URL iff we found them; otherwise base
|
# Toss back the data if we care about it
|
||||||
return (url if has_all else base, has_all)
|
if error and return_data:
|
||||||
|
return ((jobs, artifacts), False)
|
||||||
|
|
||||||
|
# Only set the url if we have everything we need
|
||||||
|
assert not error
|
||||||
|
return (url, True)
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
# If anything goes wrong, retry later with the same base URL
|
# If anything goes wrong, retry later with the same base URL
|
||||||
|
|||||||
Reference in new issue
Block a user