Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check version number asynchronously #3185

Merged
merged 11 commits into from
Feb 3, 2024
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.1
0.6.1
54 changes: 0 additions & 54 deletions bookwyrm/management/commands/instance_version.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-01-02 19:36

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0191_merge_20240102_0326"),
]

operations = [
migrations.RenameField(
model_name="sitesettings",
old_name="version",
new_name="available_version",
),
]
13 changes: 13 additions & 0 deletions bookwyrm/migrations/0194_merge_20240203_1619.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.23 on 2024-02-03 16:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0192_rename_version_sitesettings_available_version"),
("bookwyrm", "0193_merge_20240203_1539"),
]

operations = []
16 changes: 15 additions & 1 deletion bookwyrm/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
from django.utils import timezone
from model_utils import FieldTracker

from bookwyrm.connectors.abstract_connector import get_data
from bookwyrm.preview_images import generate_site_preview_image_task
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, STATIC_FULL_URL
from bookwyrm.settings import RELEASE_API
from bookwyrm.tasks import app, MISC
from .base_model import BookWyrmModel, new_access_code
from .user import User
from .fields import get_absolute_url
Expand Down Expand Up @@ -45,7 +48,7 @@ class SiteSettings(SiteModel):
default_theme = models.ForeignKey(
"Theme", null=True, blank=True, on_delete=models.SET_NULL
)
version = models.CharField(null=True, blank=True, max_length=10)
available_version = models.CharField(null=True, blank=True, max_length=10)

# admin setup options
install_mode = models.BooleanField(default=False)
Expand Down Expand Up @@ -245,3 +248,14 @@ def preview_image(instance, *args, **kwargs):

if len(changed_fields) > 0:
generate_site_preview_image_task.delay()


@app.task(queue=MISC)
def check_for_updates_task():
"""See if git remote knows about a new version"""
site = SiteSettings.objects.get()
release = get_data(RELEASE_API, timeout=3)
available_version = release.get("tag_name", None)
if available_version:
site.available_version = available_version
site.save(update_fields=["available_version"])
4 changes: 4 additions & 0 deletions bookwyrm/templates/settings/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ <h3>{% trans "Works" %}</h3>
{% include 'settings/dashboard/warnings/update_version.html' with warning_level="warning" fullwidth=True %}
{% endif %}

{% if schedule_form %}
{% include 'settings/dashboard/warnings/check_for_updates.html' with warning_level="success" fullwidth=True %}
{% endif %}

{% if missing_privacy or missing_conduct %}
<div class="column is-12 columns m-0 p-0">
{% if missing_privacy %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'settings/dashboard/warnings/layout.html' %}
{% load i18n %}

{% block warning_link %}#{% endblock %}

{% block warning_text %}

<form name="check-version" method="POST" action="{% url 'settings-dashboard' %}" class="is-flex is-align-items-center">
{% csrf_token %}

<p class="pr-2">
{% blocktrans trimmed with current=current_version available=available_version %}
Would you like to automatically check for new BookWyrm releases? (recommended)
{% endblocktrans %}
</p>

{{ schedule_form.every.as_hidden }}
{{ schedule_form.period.as_hidden }}

<button class="button is-small" type="submit">{% trans "Schedule checks" %}</button>
</form>

{% endblock %}

4 changes: 4 additions & 0 deletions bookwyrm/templates/settings/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ <h2 class="menu-label">{% trans "System" %}</h2>
{% 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>
<li>
{% url 'settings-schedules' as url %}
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Scheduled tasks" %}</a>
</li>
<li>
{% url 'settings-email-config' as url %}
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Email Configuration" %}</a>
Expand Down
127 changes: 127 additions & 0 deletions bookwyrm/templates/settings/schedules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{% extends 'settings/layout.html' %}
{% load i18n %}
{% load humanize %}
{% load utilities %}

{% block title %}
{% trans "Scheduled tasks" %}
{% endblock %}

{% block header %}
{% trans "Scheduled tasks" %}
{% endblock %}

{% block panel %}

<div class="block content">
<h3>{% trans "Tasks" %}</h3>
<div class="table-container">
<table class="table is-striped is-fullwidth">
<tr>
<th>
{% trans "Name" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice-to-have (possibly in a subsequent PR) would be to link the task name to some sort of explanation of the purpose of the task and/or what it does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Periodic tasks have a description field which we're currently not using, but presumably would be perfect for this

</th>
<th>
{% trans "Celery task" %}
</th>
<th>
{% trans "Date changed" %}
</th>
<th>
{% trans "Last run at" %}
</th>
<th>
{% trans "Schedule" %}
</th>
<th>
{% trans "Schedule ID" %}
</th>
<th>
{% trans "Enabled" %}
</th>
</tr>
{% for task in tasks %}
<tr>
<td>
{{ task.name }}
</td>
<td class="overflow-wrap-anywhere">
{{ task.task }}
</td>
<td>
{{ task.date_changed }}
</td>
<td>
{{ task.last_run_at }}
</td>
<td>
{% firstof task.interval task.crontab "None" %}
</td>
<td>
{{ task.interval.id }}
</td>
<td>
<span class="tag">
{% if task.enabled %}
<span class="icon icon-check" aria-hidden="true"></span>
{% endif %}
{{ task.enabled|yesno }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there does not seem to be a way to disable celery.backend_cleanup or check-for-updates.

Now, one might argue that they shouldn't be disabled, but it seems a bit odd that you have to manually turn on check-for-updates but then you can't turn it off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I agree, I think it should be a subsequent PR because celery.backend_cleanup might be the kind of the thing that it's Not Good to turn off

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually but now that I saw that, if someone has it running every minute, they're probably going to be displeased not to be able to stop it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could trigger a big scary banner if it's ever turned off. I don't think this needs to be a blocker for this PR, just wanted to note it for future improvement.

</span>
{% if task.name != "celery.backend_cleanup" %}
<form name="unschedule-{{ task.id }}" method="POST" action="{% url 'settings-schedules' task.id %}">
{% csrf_token %}
<button type="submit" class="button is-danger is-small">{% trans "Un-schedule" %}</button>
</form>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="2">
{% trans "No scheduled tasks" %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>

<div class="block content">
<h3>{% trans "Schedules" %}</h3>
<div class="table-container">
<table class="table is-striped is-fullwidth">
<tr>
<th>
{% trans "ID" %}
</th>
<th>
{% trans "Schedule" %}
</th>
<th>
{% trans "Tasks" %}
</th>
</tr>
{% for schedule in schedules %}
<tr>
<td>
{{ schedule.id }}
</td>
<td class="overflow-wrap-anywhere">
{{ schedule }}
</td>
<td>
{{ schedule.periodictask_set.count }}
</td>
</tr>
{% empty %}
<tr>
<td colspan="2">
{% trans "No schedules found" %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>

{% endblock %}
5 changes: 5 additions & 0 deletions bookwyrm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
re_path(
r"^settings/celery/ping/?$", views.celery_ping, name="settings-celery-ping"
),
re_path(
r"^settings/schedules/(?P<task_id>\d+)?$",
views.ScheduledTasks.as_view(),
name="settings-schedules",
),
re_path(
r"^settings/email-config/?$",
views.EmailConfig.as_view(),
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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, celery_ping
from .admin.schedule import ScheduledTasks
from .admin.dashboard import Dashboard
from .admin.federation import Federation, FederatedServer
from .admin.federation import AddFederatedServer, ImportServerBlocklist
Expand Down
4 changes: 2 additions & 2 deletions bookwyrm/views/admin/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.http import require_POST
from django_celery_beat.models import PeriodicTask
from django_celery_beat.models import PeriodicTask, IntervalSchedule

from bookwyrm import forms, models

Expand Down Expand Up @@ -54,7 +54,7 @@ def schedule_automod_task(request):
return TemplateResponse(request, "settings/automod/rules.html", data)

with transaction.atomic():
schedule = form.save(request)
schedule, _ = IntervalSchedule.objects.get_or_create(**form.cleaned_data)
PeriodicTask.objects.get_or_create(
interval=schedule,
name="automod-task",
Expand Down
Loading
Loading