diff --git a/comm/server/main.py b/comm/server/main.py index 232ee8e43c2202a17229a53c2cb6837bf9d2f5dd..5f98e468e2e5a3e65148474a4439103634e8b548 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -59,6 +59,7 @@ def load_questions(): "queue": Queue(), "board_size": board_size, "line_num": line_num, + "last_req": None, "answers": [], } @@ -112,18 +113,17 @@ def post(): global questions global app_args - _client = request.form["client"] _qname = request.form["qname"] _answer = request.form["answer"] - _cputime = request.form["cputime"] receive_time = datetime.datetime.now() receive_time_str = receive_time.strftime("%Y%m%d%H%M%S") dat = { - "client": _client, + "req_id": request.form['req_id'], + "client": request.form['client'], "answer": _answer, - "cputime": _cputime, + "cputime": request.form['cputime'], "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S") } @@ -218,26 +218,29 @@ def solve_questions(qname, qstr): global clients global questions global current_seed - global app_args - def worker(host, qname, qstr, qseed, request_time): + def worker(host, qname, qstr, qseed, req_id): _url = "http://{}/start".format(host) try: - r = requests.post(_url, data={"client": host, "qname": qname, "question": qstr, "qseed": qseed, "request_time": request_time}) + r = requests.post(_url, data={"client": host, "qname": qname, "question": qstr, "qseed": qseed, "req_id": req_id}) client_res = json.loads(r.text) except Exception as e: sys.stderr.write(str(e) + "\n") threads = [] - request_time = time.time() + # 時刻をリクエストIDとして設定 + req_id = time.time() + questions[qname]['last_req'] = req_id for c in clients: - client_addr = c[0] - _th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, request_time)) - _th.start() - threads.append(_th) - current_seed += 1 + # 問題はSolverに送る + if c[1] == 'Solver': + client_addr = c[0] + _th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, req_id)) + _th.start() + threads.append(_th) + current_seed += 1 res = {"status": "Processed"}