Adds a ping-able celery url

This will let admins set up a check to notify you if celery is not
running.
This commit is contained in:
Mouse Reeve 2023-01-30 08:27:40 -08:00
parent d0a0851123
commit c1090703e2
3 changed files with 21 additions and 1 deletions

View file

@ -329,6 +329,9 @@ urlpatterns = [
re_path(
r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery"
),
re_path(
r"^settings/celery/ping?$", views.celery_ping, name="settings-celery-ping"
),
re_path(
r"^settings/email-config/?$",
views.EmailConfig.as_view(),

View file

@ -4,7 +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.celery_status import CeleryStatus, celery_ping
from .admin.dashboard import Dashboard
from .admin.federation import Federation, FederatedServer
from .admin.federation import AddFederatedServer, ImportServerBlocklist

View file

@ -1,8 +1,10 @@
""" 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
@ -50,3 +52,18 @@ class CeleryStatus(View):
"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(500)