{% extends "layout.html" %}

{% block body %}
    <form method="POST">
        <table>
            <tr>
                <th>Hostname</th>
                <th>IP</th>
                <th>Port</th>
                <th>Uptime</th>
                <th>PID</th>
                <th>PPID</th>
                <th>Version</th>
                <th>Queue</th>
                <th>Consuming</th>
                <th>Current Task</th>
                <th>Args</th>
                <th>Kwargs</th>
                <th>Actions</th>
            </tr>
            {% for addr, master in sockets|dictsort(by='value') %}
            <tr>
                <td>{{ master.stats.hostname }}</td>
                <td>{{ addr[0] }}</td>
                <td>{{ addr[1] }}</td>
                <td
                  {# Higlight over working workers #}
                  {% if config['MAX_WORKER_RUN_TIME'] and master.stats.uptime > config['MAX_WORKER_RUN_TIME'] %}
                    style="background-color: yellow"
                  {% endif %}>

                  {{ human_time(master.stats.uptime) }}
                </td>
                <td>{{ master.stats.pid }}</td>
                <td>{{ master.stats.ppid }}</td>
                <td>{{ master.stats.version }}</td>
                <td>{{ master.stats.queue.name }}</td>
                <td>{{ master.stats.consuming }}</td>
                <td>{{ master.stats.current_task|default('', true) }}</td>
                <td>{{ master.stats.current_args|default('', true) }}</td>
                <td>{{ master.stats.current_kwargs|default('', true) }}</td>
                <td>
                    {{ action_button(addr, 'warm_shutdown', 'Warm Shutdown') }}
                    {{ action_button(addr, 'cold_shutdown', 'Cold Shutdown') }}
                    {{ action_button(addr, 'quit_task', 'Quit Task') }}
                </td>
            </tr>
            {% endfor %}

            {% if not request.args.ppid %}
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>
                    {{ action_button_all('worker', 'warm_shutdown', 'Warm Shutdown All') }}
                    {{ action_button_all('worker', 'cold_shutdown', 'Cold Shutdown All') }}
                </td>
            </tr>
            {% endif %}
        </table>
        Count: {{ sockets|count }}
    </form>
{% endblock %}
