Simplify the mess about having a json containing all result ... just create a new route that concatenates all latest results of all apps on the fly

This commit is contained in:
Alexandre Aubin 2023-03-03 22:24:22 +01:00
parent 6c35960435
commit 4d8643b223

33
run.py
View file

@ -713,21 +713,6 @@ async def run_job(worker, job):
shutil.copy(
summary_png, yunorunner_dir + f"/results/summary/{job.id}.png"
)
public_result_json_path = (
yunorunner_dir
+ f"/results/logs/list_level_{app.config.YNH_BRANCH}_{app.config.ARCH}.json"
)
if (
not os.path.exists(public_result_json_path)
or not open(public_result_json_path).read().strip()
):
public_result = {}
else:
public_result = json.load(open(public_result_json_path))
public_result[job_app] = results
open(public_result_json_path, "w").write(json.dumps(public_result))
finally:
job.end_time = datetime.now()
@ -1314,6 +1299,24 @@ async def api_restart_job(request, job_id):
return response.text("ok")
@app.route("/api/results", methods=["GET"])
async def api_results(request):
repos = Repo.select().order_by(Repo.name)
all_results = {}
for repo in repos:
latest_result_path = yunorunner_dir + f"/results/logs/{repo.name}_{app.config.ARCH}_{app.config.YNH_BRANCH}_results.json"
if not os.path.exists(latest_result_path):
continue
all_results[repo.name] = json.load(open(latest_result_path))
return response.json(all_results)
# Meant to interface with https://shields.io/endpoint
@app.route("/api/job/<job_id:int>/badge", methods=["GET"])
async def api_badge_job(request, job_id):