From c1090703e2f25901657fc7aac8ef543b8ba7408b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 Jan 2023 08:27:40 -0800 Subject: [PATCH 1/7] Adds a ping-able celery url This will let admins set up a check to notify you if celery is not running. --- bookwyrm/urls.py | 3 +++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/admin/celery_status.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 73bdd3755..9828936e1 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -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(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 353275c46..cbc7998fa 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -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 diff --git a/bookwyrm/views/admin/celery_status.py b/bookwyrm/views/admin/celery_status.py index 0e88f55f1..61fedd341 100644 --- a/bookwyrm/views/admin/celery_status.py +++ b/bookwyrm/views/admin/celery_status.py @@ -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) From 8f88b72620136fddafbef9e74914b7b373793bdb Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 Jan 2023 08:35:24 -0800 Subject: [PATCH 2/7] Adds info about celery endpoint in admin view --- bookwyrm/templates/settings/celery.html | 8 ++++++++ bookwyrm/urls.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/settings/celery.html b/bookwyrm/templates/settings/celery.html index 7ce6553fb..6a3ee6574 100644 --- a/bookwyrm/templates/settings/celery.html +++ b/bookwyrm/templates/settings/celery.html @@ -9,6 +9,14 @@ {% block panel %} +
+

+ {% trans "You can set up monitoring to check if Celery is running by querying:" %} + {% url "settings-celery-ping" as url %} + {{ url }} +

+
+ {% if queues %}

{% trans "Queues" %}

diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 9828936e1..79671edae 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -330,7 +330,7 @@ urlpatterns = [ r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery" ), re_path( - r"^settings/celery/ping?$", views.celery_ping, name="settings-celery-ping" + r"^settings/celery/ping/?$", views.celery_ping, name="settings-celery-ping" ), re_path( r"^settings/email-config/?$", From aecd4d2a4fe7b49a9c43229e07fde2a2b16823db Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Thu, 2 Feb 2023 12:36:34 +0100 Subject: [PATCH 3/7] Upgrade development black to 22.12.0 --- dev-tools/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/requirements.txt b/dev-tools/requirements.txt index a84bf64b2..a69d319ab 100644 --- a/dev-tools/requirements.txt +++ b/dev-tools/requirements.txt @@ -1 +1 @@ -black==22.3.0 +black==22.12.0 From 60a0075bf4b9741289103672dce93bb5889e495b Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Thu, 2 Feb 2023 12:36:46 +0100 Subject: [PATCH 4/7] Pin Github Actions black to 22.12.0 --- .github/workflows/black.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 95a0ebfb0..4e7be4af3 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -13,3 +13,5 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - uses: psf/black@22.12.0 + with: + version: 22.12.0 From 22eeee7368e0a7d54451b1a86e28e38b2887db8c Mon Sep 17 00:00:00 2001 From: 0x29a Date: Thu, 2 Feb 2023 21:02:57 +0100 Subject: [PATCH 5/7] Urlencode search query --- bookwyrm/connectors/abstract_connector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 6dd8a3081..0e04ffaf2 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -1,5 +1,6 @@ """ functionality outline for a book data connector """ from abc import ABC, abstractmethod +from urllib.parse import quote_plus import imghdr import logging import re @@ -48,7 +49,7 @@ class AbstractMinimalConnector(ABC): return f"{self.isbn_search_url}{normalized_query}" # NOTE: previously, we tried searching isbn and if that produces no results, # searched as free text. This, instead, only searches isbn if it's isbn-y - return f"{self.search_url}{query}" + return f"{self.search_url}{quote_plus(query)}" def process_search_response(self, query, data, min_confidence): """Format the search results based on the formt of the query""" From fd59fea94ea4b8ca8ba3dc914ccec91e3ee49426 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 2 Feb 2023 16:46:36 -0800 Subject: [PATCH 6/7] Update bookwyrm/views/admin/celery_status.py Co-authored-by: Christof Dorner --- bookwyrm/views/admin/celery_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/admin/celery_status.py b/bookwyrm/views/admin/celery_status.py index 61fedd341..8c6b9f5a3 100644 --- a/bookwyrm/views/admin/celery_status.py +++ b/bookwyrm/views/admin/celery_status.py @@ -66,4 +66,4 @@ def celery_ping(request): except Exception: pass - return HttpResponse(500) + return HttpResponse(status=500) From b43f1eab38717cf60f160258b5215c649656205a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:18:41 +0000 Subject: [PATCH 7/7] Bump django from 3.2.16 to 3.2.17 Bumps [django](https://github.com/django/django) from 3.2.16 to 3.2.17. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/3.2.16...3.2.17) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e71fb52c8..ab45e08a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ aiohttp==3.8.3 bleach==5.0.1 celery==5.2.7 colorthief==0.2.1 -Django==3.2.16 +Django==3.2.17 django-celery-beat==2.4.0 django-compressor==4.3.1 django-imagekit==4.1.0