mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
Adds celery status view
This commit is contained in:
parent
fcf796abe1
commit
0f55b76a93
6 changed files with 119 additions and 0 deletions
59
bookwyrm/templates/settings/celery.html
Normal file
59
bookwyrm/templates/settings/celery.html
Normal file
|
@ -0,0 +1,59 @@
|
|||
{% extends 'settings/layout.html' %}
|
||||
{% load humanize %}
|
||||
{% load i18n %}
|
||||
{% load celery_tags %}
|
||||
|
||||
{% block title %}{% trans "Celery Status" %}{% endblock %}
|
||||
|
||||
{% block header %}{% trans "Celery Status" %}{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% if stats %}
|
||||
<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>
|
||||
|
||||
|
||||
<section class="block content">
|
||||
<h2>{% trans "Active Tasks" %}</h2>
|
||||
{% for worker in active_tasks.values %}
|
||||
<div class="table-container">
|
||||
<table class="table is-striped is-fullwidth">
|
||||
<tr>
|
||||
<th>{% trans "ID" %}</th>
|
||||
<th>{% trans "Task name" %}</th>
|
||||
<th>{% trans "Start time" %}</th>
|
||||
<th>{% trans "Priority" %}</th>
|
||||
</tr>
|
||||
{% for task in worker %}
|
||||
<tr>
|
||||
<td>{{ task.id }}</td>
|
||||
<td>{{ task.name|shortname }}</td>
|
||||
<td>{{ task.time_start|datestamp }} (UTC)</td>
|
||||
<td>{{ task.delivery_info.routing_key }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</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 Celery" %}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -74,6 +74,15 @@
|
|||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% if perms.edit_instance_settings %}
|
||||
<h2 class="menu-label">{% trans "System" %}</h2>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
{% url 'settings-celery' as url %}
|
||||
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Celery status" %}</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% if perms.bookwyrm.edit_instance_settings %}
|
||||
<h2 class="menu-label">{% trans "Instance Settings" %}</h2>
|
||||
<ul class="menu-list">
|
||||
|
|
24
bookwyrm/templatetags/celery_tags.py
Normal file
24
bookwyrm/templatetags/celery_tags.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
""" template filters for really common utilities """
|
||||
import datetime
|
||||
from django import template
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name="uptime")
|
||||
def uptime(seconds):
|
||||
"""Seconds uptime to a readable format"""
|
||||
return str(datetime.timedelta(seconds=seconds))
|
||||
|
||||
|
||||
@register.filter(name="datestamp")
|
||||
def get_date(timestamp):
|
||||
"""Go from a string timestamp to a date object"""
|
||||
return datetime.datetime.fromtimestamp(timestamp)
|
||||
|
||||
|
||||
@register.filter(name="shortname")
|
||||
def shortname(name):
|
||||
"""removes bookwyrm.celery..."""
|
||||
return ".".join(name.split(".")[-2:])
|
|
@ -291,6 +291,9 @@ urlpatterns = [
|
|||
views.Report.as_view(),
|
||||
name="report-link",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery"
|
||||
),
|
||||
# landing pages
|
||||
re_path(r"^about/?$", views.about, name="about"),
|
||||
re_path(r"^privacy/?$", views.privacy, name="privacy"),
|
||||
|
|
|
@ -4,6 +4,7 @@ from .admin.announcements import Announcements, Announcement
|
|||
from .admin.announcements import EditAnnouncement, delete_announcement
|
||||
from .admin.automod import AutoMod, automod_delete, run_automod
|
||||
from .admin.automod import schedule_automod_task, unschedule_automod_task
|
||||
from .admin.celery_status import CeleryStatus
|
||||
from .admin.dashboard import Dashboard
|
||||
from .admin.federation import Federation, FederatedServer
|
||||
from .admin.federation import AddFederatedServer, ImportServerBlocklist
|
||||
|
|
23
bookwyrm/views/admin/celery_status.py
Normal file
23
bookwyrm/views/admin/celery_status.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
""" manage site settings """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm.tasks import app as celery
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(
|
||||
permission_required("bookwyrm.edit_instance_settings", raise_exception=True),
|
||||
name="dispatch",
|
||||
)
|
||||
class CeleryStatus(View):
|
||||
"""manage things like the instance name"""
|
||||
|
||||
def get(self, request):
|
||||
"""edit form"""
|
||||
inspect = celery.control.inspect()
|
||||
data = {"stats": inspect.stats(), "active_tasks": inspect.active()}
|
||||
return TemplateResponse(request, "settings/celery.html", data)
|
Loading…
Reference in a new issue