From 52f168a66384ed9d8799e9ce4b209bd2058d9050 Mon Sep 17 00:00:00 2001 From: Kento HASEGAWA Date: Fri, 23 Aug 2019 16:34:46 +0900 Subject: [PATCH] Make it possible to stop/reset a worker --- roles/host.py | 16 ++++++++++++-- static/js/adc2019.js | 34 ++++++++++++++++++++++++++++-- templates/index.html | 2 +- templates/part_system_summary.html | 7 +++++- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/roles/host.py b/roles/host.py index 1053533..218b39b 100644 --- a/roles/host.py +++ b/roles/host.py @@ -174,6 +174,12 @@ class Host(object): elif cmd == 'cancel': self.worker_manager.request_cancel(params) return {'status': 'canceled'} + elif cmd == 'worker/reset': + self.worker_manager.reset_worker(params['address']) + return {'status': 'reset'} + elif cmd == 'worker/stop': + self.worker_manager.request_stop(params['address']) + return {'status': 'stopped'} elif cmd == 'worker/status': self.worker_manager.update_status(params['address'], params['status']) return {'status': 'updated'} @@ -256,9 +262,15 @@ class WorkerManager(object): def update_status(self, address, status): self.workers[address].status = status + + def reset_worker(self, address): + self.workers[address].configure() - def request_stop(self): - self.broadcast('stop', {}) + def request_stop(self, address=None): + if address is None: + self.broadcast('stop', {}) + else: + self.workers[address].post('stop', {}) def request_cancel(self, params): self.broadcast('cancel', params) diff --git a/static/js/adc2019.js b/static/js/adc2019.js index ad90cb7..c0b8916 100644 --- a/static/js/adc2019.js +++ b/static/js/adc2019.js @@ -78,8 +78,11 @@ class StatusView { var _val = $(el).val(); solvers.push(_val); }); - - console.log(solvers); + + if(solvers.length == 0){ + alert("At least one solver must be selected."); + return; + } $.ajax({ type: "POST", @@ -208,6 +211,33 @@ class StatusView { alert(data['message']); }); }; + + var button_action_with_ajax_post = function($obj, url, param){ + $obj.prop("disabled", "disabled"); + $.ajax({ + type: "POST", + url: url, + dataType: "json", + data: JSON.stringify(param), + contentType: 'application/json' + }).done((data)=>{ + $obj.prop("disabled", false); + alert(data['status']); + }); + }; + + $(".btn-worker-reset").click(function(){ + var param = { + "address": $(this).data('worker') + }; + button_action_with_ajax_post($(this), "/api/worker/reset", param); + }); + $(".btn-worker-stop").click(function(){ + var param = { + "address": $(this).data('worker') + }; + button_action_with_ajax_post($(this), "/api/worker/stop", param); + }); $("#adccli-login-button").click(function(){ button_action_with_ajax($(this), "/adccli-login"); diff --git a/templates/index.html b/templates/index.html index 7b451b0..2b908a7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,7 +22,7 @@

問題一覧

  - システム状況 + システム設定

Loading...

diff --git a/templates/part_system_summary.html b/templates/part_system_summary.html index 275c74f..ca2c65b 100644 --- a/templates/part_system_summary.html +++ b/templates/part_system_summary.html @@ -1,4 +1,4 @@ -

システム状況

+

システム設定

動作モード

@@ -28,6 +28,7 @@ Worker Role Status + Cmd {% for k, w in workers.items() %} @@ -36,6 +37,10 @@ {{w.role}} {{w.status}} + + + + {% endfor %} -- 2.22.0