Commit a350ed9a authored by Kento HASEGAWA's avatar Kento HASEGAWA
Browse files

Use req_id to identify the processing question

parent fa33ab65
Loading
Loading
Loading
Loading
+12 −9
Changes for comm/server/main.py: 12 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -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,23 +218,26 @@ 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:
        # 問題はSolverに送る
        if c[1] == 'Solver':
            client_addr = c[0]
        _th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, request_time))
            _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