Merge branch 'main' into gts
This commit is contained in:
commit
a0b7112c9c
74 changed files with 298 additions and 169 deletions
|
@ -1,10 +1,13 @@
|
|||
""" celery status """
|
||||
import json
|
||||
|
||||
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
|
||||
from django import forms
|
||||
import redis
|
||||
|
||||
from celerywyrm import settings
|
||||
|
@ -46,21 +49,68 @@ class CeleryStatus(View):
|
|||
queues = None
|
||||
errors.append(err)
|
||||
|
||||
form = ClearCeleryForm()
|
||||
|
||||
data = {
|
||||
"stats": stats,
|
||||
"active_tasks": active_tasks,
|
||||
"queues": queues,
|
||||
"form": form,
|
||||
"errors": errors,
|
||||
}
|
||||
return TemplateResponse(request, "settings/celery.html", data)
|
||||
|
||||
def post(self, request):
|
||||
"""Submit form to clear queues"""
|
||||
form = ClearCeleryForm(request.POST)
|
||||
if form.is_valid():
|
||||
if len(celery.control.ping()) != 0:
|
||||
return HttpResponse(
|
||||
"Refusing to delete tasks while Celery worker is active"
|
||||
)
|
||||
pipeline = r.pipeline()
|
||||
for queue in form.cleaned_data["queues"]:
|
||||
for task in r.lrange(queue, 0, -1):
|
||||
task_json = json.loads(task)
|
||||
if task_json["headers"]["task"] in form.cleaned_data["tasks"]:
|
||||
pipeline.lrem(queue, 0, task)
|
||||
results = pipeline.execute()
|
||||
|
||||
return HttpResponse(f"Deleted {sum(results)} tasks")
|
||||
|
||||
|
||||
class ClearCeleryForm(forms.Form):
|
||||
"""Form to clear queues"""
|
||||
|
||||
queues = forms.MultipleChoiceField(
|
||||
label="Queues",
|
||||
choices=[
|
||||
(LOW, "Low prioirty"),
|
||||
(MEDIUM, "Medium priority"),
|
||||
(HIGH, "High priority"),
|
||||
(IMPORTS, "Imports"),
|
||||
(BROADCAST, "Broadcasts"),
|
||||
],
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
tasks = forms.MultipleChoiceField(
|
||||
label="Tasks", choices=[], widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
celery.loader.import_default_modules()
|
||||
self.fields["tasks"].choices = sorted(
|
||||
[(k, k) for k in celery.tasks.keys() if not k.startswith("celery.")]
|
||||
)
|
||||
|
||||
|
||||
@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()
|
||||
ping = celery.control.inspect().ping(timeout=5)
|
||||
if ping:
|
||||
return HttpResponse()
|
||||
# pylint: disable=broad-except
|
||||
|
|
|
@ -76,7 +76,7 @@ class Dashboard(View):
|
|||
|
||||
|
||||
def get_charts_and_stats(request):
|
||||
"""Defines the dashbaord charts"""
|
||||
"""Defines the dashboard charts"""
|
||||
interval = int(request.GET.get("days", 1))
|
||||
now = timezone.now()
|
||||
start = request.GET.get("start")
|
||||
|
|
|
@ -154,7 +154,7 @@ def add_authors(request, data):
|
|||
data["author_matches"] = []
|
||||
data["isni_matches"] = []
|
||||
|
||||
# creting a book or adding an author to a book needs another step
|
||||
# creating a book or adding an author to a book needs another step
|
||||
data["confirm_mode"] = True
|
||||
# this isn't preserved because it isn't part of the form obj
|
||||
data["remove_authors"] = request.POST.getlist("remove_authors")
|
||||
|
|
|
@ -103,7 +103,7 @@ def raise_is_blocked_activity(activity_json):
|
|||
|
||||
def sometimes_async_activity_task(activity_json, queue=MEDIUM):
|
||||
"""Sometimes we can effectively respond to a request without queuing a new task,
|
||||
and whever that is possible, we should do it."""
|
||||
and whenever that is possible, we should do it."""
|
||||
activity = activitypub.parse(activity_json)
|
||||
|
||||
# try resolving this activity without making any http requests
|
||||
|
|
|
@ -14,7 +14,7 @@ from bookwyrm.views.list.list import normalize_book_list_ordering
|
|||
# pylint: disable=no-self-use
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class Curate(View):
|
||||
"""approve or discard list suggestsions"""
|
||||
"""approve or discard list suggestions"""
|
||||
|
||||
def get(self, request, list_id):
|
||||
"""display a pending list"""
|
||||
|
|
|
@ -14,7 +14,7 @@ from bookwyrm.settings import PAGE_LENGTH
|
|||
|
||||
# pylint: disable=no-self-use
|
||||
class EmbedList(View):
|
||||
"""embeded book list page"""
|
||||
"""embedded book list page"""
|
||||
|
||||
def get(self, request, list_id, list_key):
|
||||
"""display a book list"""
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.db import transaction
|
|||
from django.db.models import Avg, DecimalField, Q, Max
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.http import HttpResponseBadRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
|
@ -183,7 +183,7 @@ def delete_list(request, list_id):
|
|||
book_list.raise_not_deletable(request.user)
|
||||
|
||||
book_list.delete()
|
||||
return redirect_to_referer(request, "lists")
|
||||
return redirect("/list")
|
||||
|
||||
|
||||
@require_POST
|
||||
|
|
|
@ -186,7 +186,7 @@ def update_readthrough_on_shelve(
|
|||
active_readthrough = models.ReadThrough.objects.create(
|
||||
user=user, book=annotated_book
|
||||
)
|
||||
# santiize and set dates
|
||||
# sanitize and set dates
|
||||
active_readthrough.start_date = load_date_in_user_tz_as_utc(start_date, user)
|
||||
# if the stop or finish date is set, the readthrough will be set as inactive
|
||||
active_readthrough.finish_date = load_date_in_user_tz_as_utc(finish_date, user)
|
||||
|
|
|
@ -232,7 +232,7 @@ def find_mentions(user, content):
|
|||
if not content:
|
||||
return {}
|
||||
# The regex has nested match groups, so the 0th entry has the full (outer) match
|
||||
# And beacuse the strict username starts with @, the username is 1st char onward
|
||||
# And because the strict username starts with @, the username is 1st char onward
|
||||
usernames = [m[0][1:] for m in re.findall(regex.STRICT_USERNAME, content)]
|
||||
|
||||
known_users = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue