forked from mirrors/bookwyrm
Retry hanging items
This commit is contained in:
parent
f92863ad3e
commit
8cede05d32
4 changed files with 31 additions and 6 deletions
|
@ -35,9 +35,9 @@ class ImportJob(models.Model):
|
||||||
|
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
created_date = models.DateTimeField(default=timezone.now)
|
created_date = models.DateTimeField(default=timezone.now)
|
||||||
|
updated_date = models.DateTimeField(default=timezone.now)
|
||||||
include_reviews = models.BooleanField(default=True)
|
include_reviews = models.BooleanField(default=True)
|
||||||
mappings = models.JSONField()
|
mappings = models.JSONField()
|
||||||
updated_date = models.DateTimeField(default=timezone.now)
|
|
||||||
complete = models.BooleanField(default=False)
|
complete = models.BooleanField(default=False)
|
||||||
source = models.CharField(max_length=100)
|
source = models.CharField(max_length=100)
|
||||||
privacy = models.CharField(
|
privacy = models.CharField(
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if not complete %}
|
{% if not job.complete %}
|
||||||
<div class="box is-processing">
|
<div class="box is-processing">
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<span class="icon icon-spinner is-pulled-left" aria-hidden="true"></span>
|
<span class="icon icon-spinner is-pulled-left" aria-hidden="true"></span>
|
||||||
|
@ -167,8 +167,17 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<div class="is-flex">
|
||||||
<span class="icon icon-dots-three" aria-hidden="true"></span>
|
<span class="icon icon-dots-three" aria-hidden="true"></span>
|
||||||
<span class="is-sr-only-mobile">{% trans "Pending" %}</span>
|
<span class="is-sr-only-mobile">{% trans "Pending" %}</span>
|
||||||
|
{# retry option if an item appears to be hanging #}
|
||||||
|
{% if job.created_date != job.updated_date and inactive_time > 0.24 %}
|
||||||
|
<form class="ml-2" method="POST" action="{% url 'import-item-retry' job.id item.id %}" name="retry-{{ item.id }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button is-danger is-outlined is-small">{% trans "Retry" %}</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -242,6 +242,11 @@ urlpatterns = [
|
||||||
views.ImportStatus.as_view(),
|
views.ImportStatus.as_view(),
|
||||||
name="import-status",
|
name="import-status",
|
||||||
),
|
),
|
||||||
|
re_path(
|
||||||
|
r"^import/(?P<job_id>\d+)/retry/(?P<item_id>\d+)/?$",
|
||||||
|
views.ImportStatus.as_view(),
|
||||||
|
name="import-item-retry",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^import/(?P<job_id>\d+)/failed/?$",
|
r"^import/(?P<job_id>\d+)/failed/?$",
|
||||||
views.ImportTroubleshoot.as_view(),
|
views.ImportTroubleshoot.as_view(),
|
||||||
|
|
|
@ -4,12 +4,14 @@ import math
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
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.template.response import TemplateResponse
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
from bookwyrm.importers.importer import import_item_task
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
|
@ -40,10 +42,19 @@ class ImportStatus(View):
|
||||||
"page_range": paginated.get_elided_page_range(
|
"page_range": paginated.get_elided_page_range(
|
||||||
page.number, on_each_side=2, on_ends=1
|
page.number, on_each_side=2, on_ends=1
|
||||||
),
|
),
|
||||||
"complete": not job.pending_items.exists(),
|
|
||||||
"percent": math.floor( # pylint: disable=c-extension-no-member
|
"percent": math.floor( # pylint: disable=c-extension-no-member
|
||||||
(item_count - job.pending_items.count()) / item_count * 100
|
(item_count - job.pending_items.count()) / item_count * 100
|
||||||
),
|
),
|
||||||
|
# hours since last import item update
|
||||||
|
"inactive_time": (job.updated_date - timezone.now()).seconds / 60 / 60,
|
||||||
}
|
}
|
||||||
|
|
||||||
return TemplateResponse(request, "import/import_status.html", data)
|
return TemplateResponse(request, "import/import_status.html", data)
|
||||||
|
|
||||||
|
def post(self, request, job_id, item_id):
|
||||||
|
"""retry an item"""
|
||||||
|
item = get_object_or_404(
|
||||||
|
models.ImportItem, id=item_id, job__id=job_id, job__user=request.user
|
||||||
|
)
|
||||||
|
import_item_task.delay(item.id)
|
||||||
|
return redirect("import-status", job_id)
|
||||||
|
|
Loading…
Reference in a new issue