diff --git a/comm/server/main.py b/comm/server/main.py index c6363aabca1331f92d08953a45a452afdc2ec6cd..06b627f692f27e6c822b12b4d9a9a7606305e921 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -117,12 +117,18 @@ def post(): _answer = request.form["answer"] _client = request.form["client"] + if "solver" in request.form: + _solver = request.form["solver"] + else: + _solver = _client + receive_time = datetime.datetime.now() receive_time_str = receive_time.strftime("%Y%m%d%H%M%S") dat = { "req_id": request.form['req_id'], "client": _client, + "solver": _solver, "answer": _answer, "cputime": request.form['cputime'], "timestamp": receive_time.strftime("%Y/%m/%d %H:%M:%S") @@ -220,10 +226,18 @@ def solve_questions(qname, qstr): global questions global current_seed - def worker(host, qname, qstr, qseed, req_id): + def worker(host, qname, qstr, qseed, req_id, resolver): _url = "http://{}/start".format(host) + data = { + "client": host, + "qname": qname, + "question": qstr, + "qseed": qseed, + "req_id": req_id, + "resolver": resolver + } try: - r = requests.post(_url, data={"client": host, "qname": qname, "question": qstr, "qseed": qseed, "req_id": req_id}) + r = requests.post(_url, data=data) client_res = json.loads(r.text) except Exception as e: sys.stderr.write(str(e) + "\n") @@ -234,14 +248,15 @@ def solve_questions(qname, qstr): req_id = time.time() questions[qname]['last_req'] = req_id - for c in clients: + for c in clients['solver']: # 問題は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 + client_addr = c[0] + idx_of_resolver = current_seed % len(clients['resolver']) + resolver = clients['resolver'][idx_of_resolver][0] + _th = threading.Thread(name=client_addr, target=worker, args=(client_addr, qname, qstr, current_seed, req_id, resolver)) + _th.start() + threads.append(_th) + current_seed += 1 res = {"status": "Processed"} @@ -269,7 +284,7 @@ def get_clients(): res = OrderedDict() - for c in clients: + for c in clients['all']: client_ip = c[0] res[client_ip] = "http://{}".format(client_ip) @@ -291,7 +306,7 @@ def client_table(): global app_args global clients - return render_template("part_client_table.html", clients=clients, local_mode=g.local_mode) + return render_template("part_client_table.html", clients=clients["all"], local_mode=g.local_mode) @app.route("/get_question_status") def question_status(): @@ -305,20 +320,17 @@ def question_status(): update_answer_list(qname) qdata = questions[qname] - return render_template("part_question_status.html", qname=qname, qdata=qdata, clients=clients) + return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"]) @app.route("/") def index(): global app_args global questions - global clients question_path = os.path.abspath(app_args["question"]) - print(g.local_mode) - - return render_template("index.html", questions=questions, question_path=question_path, clients=clients) + return render_template("index.html", questions=questions, question_path=question_path) def main(args): raise NotImprementedError() @@ -337,7 +349,21 @@ def init_system(): with open(app_args["client"], "r") as fp: _clients = fp.readlines() - clients = [v.rstrip().split() for v in _clients] + all_clients = [v.rstrip().split() for v in _clients] + + solver = [] + resolver = [] + for v in all_clients: + if v[1].lower() == "solver": + solver.append(v) + elif v[1].lower() == "resolver": + resolver.append(v) + + clients = { + "all": all_clients, + "solver": solver, + "resolver": resolver + } if __name__ == "__main__": diff --git a/comm/server/templates/index.html b/comm/server/templates/index.html index 24a79484577912faa30a0754b295bc1f423b09eb..bb8456d24c04405086c733e5a005ff0416e2a4f1 100644 --- a/comm/server/templates/index.html +++ b/comm/server/templates/index.html @@ -20,7 +20,7 @@
Loading...