Initial implementation of new runner architecture

This commit is contained in:
akp 2021-12-10 23:49:08 +00:00
parent f5e50b6c6d
commit 9fd93f91a1
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
9 changed files with 269 additions and 168 deletions

View file

@ -0,0 +1,47 @@
from py import Challenge
import time
import json
TASKS_STR = input()
TASKS = json.loads(TASKS_STR)
def send_result(task_id, ok, output, duration):
print(json.dumps({
"task_id": task_id,
"ok": ok,
"output": str(output) if output is not None else "",
"duration": float(duration),
}), flush=True)
for task in TASKS:
taskPart = task["part"]
task_id = task["task_id"]
run = None
if taskPart == 1:
run = lambda: Challenge.one(task["input"])
elif taskPart == 2:
run = lambda: Challenge.two(task["input"])
elif taskPart == 3:
run = lambda: Challenge.vis(task["input"], task["output_dir"])
else:
send_result(task_id, False, "unknown task part", 0)
continue
start_time = time.time()
res = None
err = None
try:
res = run()
except Exception as e:
err = f"{type(e)}: {e}"
end_time = time.time()
running_time = end_time-start_time
if err is not None:
send_result(task_id, False, err, running_time)
else:
send_result(task_id, True, res, running_time)