{% extends "base.html" %}
{% block content %}
    <table class="table">
        <thead>
        <tr>
            <th scope="col">Name</th>
            <th scope="col">Queue</th>
            <th scope="col">Deferred</th>
            <th scope="col">Queued</th>
            <th scope="col">InProgress</th>
            <th scope="col">Success</th>
            <th scope="col">Failed</th>
            <th scope="col">Expired</th>
            <th scope="col">LastAlive</th>
            <th scope="col">Information</th>
            <th scope="col">Actions</th>
        </tr>
        </thead>
        <tbody>
        {% for worker in workers %}
            <tr>
                <td>{{ worker.name }}</td>
                <td>{{ worker.queue }}</td>
                <td>{{ worker.job_stat.deferred or 0 }}</td>
                <td>{{ worker.job_stat.queued or 0 }}</td>
                <td>{{ worker.job_stat.in_progress or 0 }}</td>
                <td>{{ worker.job_stat.success or 0 }}</td>
                <td>{{ worker.job_stat.failed or 0 }}</td>
                <td>{{ worker.job_stat.expired or 0 }}</td>
                <td class="time-format">{{ worker.time }}</td>
                <td>
                    {% if worker.is_offline %}
                        <span class="badge bg-danger">offline</span>
                    {% else %}
                        <span class="badge bg-success">online</span>
                    {% endif %}
                    {% if worker.is_timer %}
                        <span class="badge bg-info">timer</span>
                    {% else %}
                        <span class="badge bg-primary">worker</span>
                    {% endif %}
                </td>
                <td>
                    <button class="btn btn-danger btn-sm" onclick="delete_worker('{{ worker.name }}')">Remove</button>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}
{% block body_end %}
    <script>
        function delete_worker(name) {
            $.ajax({
                url: "{{ url_for("rearq.delete_worker") }}?name=" + name,
                method: "DELETE",
                success: res => {
                    location.reload();
                }
            });
        }
    </script>
{% endblock %}
