Commit 52f168a6 authored by Kento HASEGAWA's avatar Kento HASEGAWA
Browse files

Make it possible to stop/reset a worker

parent fda45c9f
Loading
Loading
Loading
Loading
+13 −1
Changes for roles/host.py: 13 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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'}
@@ -257,8 +263,14 @@ class WorkerManager(object):
    def update_status(self, address, status):
        self.workers[address].status = status
        
    def request_stop(self):
    def reset_worker(self, address):
        self.workers[address].configure()

    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)
+31 −1
Changes for static/js/adc2019.js: 31 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -79,7 +79,10 @@ class StatusView {
            solvers.push(_val);
        });

        console.log(solvers);
        if(solvers.length == 0){
            alert("At least one solver must be selected.");
            return;
        }

        $.ajax({
            type: "POST",
@@ -209,6 +212,33 @@ class StatusView {
                });
            };
            
            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");
            });
+1 −1
Changes for templates/index.html: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
        <div id="content-row" class="row">
            <div class="col-5" id="content-left">
                <h3>問題一覧</h3>&nbsp;
                <span><a href="/#" id="view-server-status-button">システム状況</a></span>
                <span><a href="/#" id="view-server-status-button">システム設定</a></span>
                <div id="problem-list-container">
                    <p>Loading...</p>
                </div>
+6 −1
Changes for templates/part_system_summary.html: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
<h3>システム状況</h3>
<h3>システム設定</h3>

<div class="summary-section">
    <h4 class='inline-heading'>動作モード</h4>
@@ -28,6 +28,7 @@
            <th class="">Worker</th>
            <th class="">Role</th>
            <th class="">Status</th>
            <th class="">Cmd</th>
        </tr>
        {% for k, w in workers.items() %}
        <tr class="worker-status-row" data-cname="{{w.name}}">
@@ -36,6 +37,10 @@
            </td>
            <td class="">{{w.role}}</td>
            <td class="worker-status-value">{{w.status}}</td>
            <td>
                <button type="button" class="btn btn-danger btn-sm btn-worker-reset" data-worker="{{w.address}}">Reset</button>
                <button type="button" class="btn btn-warning btn-sm btn-worker-stop" data-worker="{{w.address}}">Stop</button>
            </td>
        </tr>
        {% endfor %}
    </table>