Show queues and runtime instead of start time
This commit is contained in:
parent
3739bdbf81
commit
d76eae358f
3 changed files with 92 additions and 16 deletions
|
@ -9,19 +9,41 @@
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
{% if stats %}
|
{% if queues %}
|
||||||
<section class="block content">
|
<section class="block content">
|
||||||
<h2>{% trans "Workers" %}</h2>
|
<h2>{% trans "Queues" %}</h2>
|
||||||
|
<div class="columns has-text-centered">
|
||||||
{% for worker_name, worker in stats.items %}
|
<div class="column is-4">
|
||||||
<div class="box">
|
<div class="notification">
|
||||||
<h3>{{ worker_name }}</h3>
|
<p class="header">{% trans "Low priority" %}</p>
|
||||||
{% trans "Uptime:" %} {{ worker.uptime|uptime }}
|
<p class="title is-5">{{ queues.low_priority|intcomma }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column is-4">
|
||||||
|
<div class="notification">
|
||||||
|
<p class="header">{% trans "Medium priority" %}</p>
|
||||||
|
<p class="title is-5">{{ queues.medium_priority|intcomma }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column is-4">
|
||||||
|
<div class="notification">
|
||||||
|
<p class="header">{% trans "High priority" %}</p>
|
||||||
|
<p class="title is-5">{{ queues.high_priority|intcomma }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
|
||||||
</section>
|
</section>
|
||||||
|
{% else %}
|
||||||
|
<div class="notification is-danger is-flex is-align-items-start">
|
||||||
|
<span class="icon icon-warning is-size-4 pr-3" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Could not connect to Redis broker" %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if stats %}
|
||||||
<section class="block content">
|
<section class="block content">
|
||||||
<h2>{% trans "Active Tasks" %}</h2>
|
<h2>{% trans "Active Tasks" %}</h2>
|
||||||
{% for worker in active_tasks.values %}
|
{% for worker in active_tasks.values %}
|
||||||
|
@ -30,14 +52,14 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "ID" %}</th>
|
<th>{% trans "ID" %}</th>
|
||||||
<th>{% trans "Task name" %}</th>
|
<th>{% trans "Task name" %}</th>
|
||||||
<th>{% trans "Start time" %}</th>
|
<th>{% trans "Run time" %}</th>
|
||||||
<th>{% trans "Priority" %}</th>
|
<th>{% trans "Priority" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for task in worker %}
|
{% for task in worker %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ task.id }}</td>
|
<td>{{ task.id }}</td>
|
||||||
<td>{{ task.name|shortname }}</td>
|
<td>{{ task.name|shortname }}</td>
|
||||||
<td>{{ task.time_start|datestamp }} (UTC)</td>
|
<td>{{ task.time_start|runtime }}</td>
|
||||||
<td>{{ task.delivery_info.routing_key }}</td>
|
<td>{{ task.delivery_info.routing_key }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -46,6 +68,17 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="block content">
|
||||||
|
<h2>{% trans "Workers" %}</h2>
|
||||||
|
|
||||||
|
{% for worker_name, worker in stats.items %}
|
||||||
|
<div class="box">
|
||||||
|
<h3>{{ worker_name }}</h3>
|
||||||
|
{% trans "Uptime:" %} {{ worker.uptime|uptime }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
<div class="notification is-danger is-flex is-align-items-start">
|
<div class="notification is-danger is-flex is-align-items-start">
|
||||||
|
@ -56,4 +89,14 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if errors %}
|
||||||
|
<div class="block content">
|
||||||
|
<h2>{% trans "Errors" %}</h2>
|
||||||
|
{% for error in errors %}
|
||||||
|
<pre>{{ error }}</pre>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -12,10 +12,10 @@ def uptime(seconds):
|
||||||
return str(datetime.timedelta(seconds=seconds))
|
return str(datetime.timedelta(seconds=seconds))
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="datestamp")
|
@register.filter(name="runtime")
|
||||||
def get_date(timestamp):
|
def runtime(timestamp):
|
||||||
"""Go from a string timestamp to a date object"""
|
"""How long has it been?"""
|
||||||
return datetime.datetime.fromtimestamp(timestamp)
|
return datetime.datetime.now() - datetime.datetime.fromtimestamp(timestamp)
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="shortname")
|
@register.filter(name="shortname")
|
||||||
|
|
|
@ -3,9 +3,17 @@ from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
import redis
|
||||||
|
|
||||||
|
from celerywyrm import settings
|
||||||
from bookwyrm.tasks import app as celery
|
from bookwyrm.tasks import app as celery
|
||||||
|
|
||||||
|
r = redis.Redis(
|
||||||
|
host=settings.REDIS_BROKER_HOST,
|
||||||
|
port=settings.REDIS_BROKER_PORT,
|
||||||
|
password=settings.REDIS_BROKER_PASSWORD,
|
||||||
|
db=settings.REDIS_BROKER_DB_INDEX,
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@ -18,6 +26,31 @@ class CeleryStatus(View):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""See workers and active tasks"""
|
"""See workers and active tasks"""
|
||||||
|
errors = []
|
||||||
|
try:
|
||||||
inspect = celery.control.inspect()
|
inspect = celery.control.inspect()
|
||||||
data = {"stats": inspect.stats(), "active_tasks": inspect.active()}
|
stats = inspect.stats()
|
||||||
|
active_tasks = inspect.active()
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception as err:
|
||||||
|
stats = active_tasks = None
|
||||||
|
errors.append(err)
|
||||||
|
|
||||||
|
try:
|
||||||
|
queues = {
|
||||||
|
"low_priority": r.llen("low_priority"),
|
||||||
|
"medium_priority": r.llen("medium_priority"),
|
||||||
|
"high_priority": r.llen("high_priority"),
|
||||||
|
}
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception as err:
|
||||||
|
queues = None
|
||||||
|
errors.append(err)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"stats": stats,
|
||||||
|
"active_tasks": active_tasks,
|
||||||
|
"queues": queues,
|
||||||
|
"errors": errors,
|
||||||
|
}
|
||||||
return TemplateResponse(request, "settings/celery.html", data)
|
return TemplateResponse(request, "settings/celery.html", data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue