mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-06-13 02:39:23 +00:00
b167364c5c
I think this will go a long way to solve the federation delay problems we're seeing on b.s. I'm not sure at what point adding more queues will create more problems than it solves, but I do think in this case the queues are out of balance and moving broadcasts (which are the most common type of `medium_priority` task at the moment) to their own queue will be an improvement.
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
""" celery status """
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
|
from django.http import HttpResponse
|
|
from django.template.response import TemplateResponse
|
|
from django.utils.decorators import method_decorator
|
|
from django.views import View
|
|
from django.views.decorators.http import require_GET
|
|
import redis
|
|
|
|
from celerywyrm import settings
|
|
from bookwyrm.tasks import app as celery, LOW, MEDIUM, HIGH, IMPORTS, BROADCAST
|
|
|
|
r = redis.from_url(settings.REDIS_BROKER_URL)
|
|
|
|
# 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):
|
|
"""Are your tasks running? Well you'd better go catch them"""
|
|
|
|
def get(self, request):
|
|
"""See workers and active tasks"""
|
|
errors = []
|
|
try:
|
|
inspect = celery.control.inspect()
|
|
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: r.llen(LOW),
|
|
MEDIUM: r.llen(MEDIUM),
|
|
HIGH: r.llen(HIGH),
|
|
IMPORTS: r.llen(IMPORTS),
|
|
BROADCAST: r.llen(BROADCAST),
|
|
}
|
|
# 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)
|
|
|
|
|
|
@require_GET
|
|
# pylint: disable=unused-argument
|
|
def celery_ping(request):
|
|
"""Just tells you if Celery is on or not"""
|
|
try:
|
|
ping = celery.control.inspect().ping()
|
|
if ping:
|
|
return HttpResponse()
|
|
# pylint: disable=broad-except
|
|
except Exception:
|
|
pass
|
|
|
|
return HttpResponse(status=500)
|