-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (46 loc) · 1.43 KB
/
Copy pathserver.py
File metadata and controls
49 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import time
import requests
from pathlib import Path
from sys import argv
from subprocess import run
def main():
config = json.loads(Path(argv[1]).read_text())
key = config["judger_key"]
server = config["server"]
sandbox = config["sandbox"]
cgroup = config["cgroup"]
judger_path = config["judger_path"]
while True:
r = requests.get(server + "/api/v1/get-submission")
if r.status_code != 200:
if r.status_code != 404:
print(r.status_code)
time.sleep(1)
continue
j = r.json()
id = j["id"]
print(f"Got task {id}")
with open("task.json", "wb") as f:
f.write(r.content)
r = requests.post(server + "/api/v1/update-submission", data={
"submission": id,
"key": key,
"status": "assigned",
"memory": "0",
"time": "0"
})
r.raise_for_status()
proc = run([judger_path, sandbox, cgroup, "task.json"], capture_output=True)
print(proc.stdout.decode())
res = json.loads(proc.stdout.decode())
r = requests.post(server + "/api/v1/update-submission", data={
"submission": id,
"key": key,
"status": res["verdict"],
"memory": str(res["memory"]),
"time": str(res["time"])
})
r.raise_for_status()
if __name__ == "__main__":
main()