From f226a4e51a6f720b0abeec168e88fcd8da201df2 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 2 Oct 2019 13:12:08 +0200 Subject: [PATCH 1/2] moved socket.emit to the live_request function --- watcher/app.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/watcher/app.py b/watcher/app.py index 8466250..01fcfd1 100644 --- a/watcher/app.py +++ b/watcher/app.py @@ -53,12 +53,13 @@ def start_run(run_index): @app.route("/link/start//") def link_start(run, link_index): + request_data = live_request(run, link_index, f'/link/start/{run}/{link_index}') #make request show up on the live requests + if not run.isdigit() or not link_index.isdigit(): return f'{run} and/or {link_index} is not a number' start = time() - request_data = live_request(run, link_index) - sio.emit('live_request', request_data) + if db["current_run"] != run: response = "Wrong run number, check that you update your run", 404 @@ -100,12 +101,14 @@ def connect(sid, data): sio.emit('sync_current_run', current_run, room=sid) -def live_request(run, index): +def live_request(run, index, route_data): ip = request.remote_addr request_data = {} request_data["hostname"] = lookup_hostname(ip) request_data["time"] = time() - return request_data + request_data["route"] = route_data + + sio.emit('live_request', request_data) @lru_cache() From 79168735896903f597742894ecc0d0efec3c6321 Mon Sep 17 00:00:00 2001 From: Hannes Klinckaert Date: Wed, 2 Oct 2019 13:22:51 +0200 Subject: [PATCH 2/2] add live requests to all valid routes --- watcher/app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/watcher/app.py b/watcher/app.py index 01fcfd1..cf275b3 100644 --- a/watcher/app.py +++ b/watcher/app.py @@ -38,6 +38,8 @@ def index(): @app.route("/start_run/") def start_run(run_index): + request_data = live_request(f'/start_run/{run_index}') #make request show up on the live requests + if not run_index.isdigit(): return f'{run_index} is not a number' @@ -53,7 +55,7 @@ def start_run(run_index): @app.route("/link/start//") def link_start(run, link_index): - request_data = live_request(run, link_index, f'/link/start/{run}/{link_index}') #make request show up on the live requests + request_data = live_request(f'/link/start/{run}/{link_index}') #make request show up on the live requests if not run.isdigit() or not link_index.isdigit(): return f'{run} and/or {link_index} is not a number' @@ -79,6 +81,8 @@ def link_start(run, link_index): @app.route("/link/handoff//") def link_handoff(run, index): + request_data = live_request(f'/link/handoff/{run}/{link_index}') #make request show up on the live requests + if not run.isdigit() or not index.isdigit(): return f'{run} and/or {index} is not a number' @@ -101,7 +105,7 @@ def connect(sid, data): sio.emit('sync_current_run', current_run, room=sid) -def live_request(run, index, route_data): +def live_request(route_data): ip = request.remote_addr request_data = {} request_data["hostname"] = lookup_hostname(ip)